QB64 Phoenix Edition
DATE$ function - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: DATE$ function (/showthread.php?tid=2060)

Pages: 1 2 3 4 5 6


RE: DATE$ function - TerryRitchie - 10-04-2023

(10-04-2023, 10:36 PM)SMcNeill Wrote: Did you try "Run as admin"?  Windows really doesn't want folks to do much tinkering on date and time anymore, as they like to sync things all nice and neat via the web.  I honestly can't think of the last time that I've ever had to manually set the date and time on any of my PCs.
And even if you do get the software to change the date and time Windows would probably just resync it a short time later any way.

I know Windows Update will fail hard if the date/time in your computer is incorrect.

I can't think of any reason why I would want to have software change the date/time. I have not had to do that since the DOS days and PCs that didn't contain a clock chip like a Dallas and battery backup. If you're writing software that changes depending on the time of day (like bplus' banner) then a quick manual forced change to trick your software into believing the time/date is different is easily done and then removed before the final version.


RE: DATE$ function - eoredson - 10-04-2023

Huh. As usual Steve, you have solved the problem for another DUH of mine.

Yes, running as admin makes it work!?

Erik.


RE: DATE$ function - eoredson - 10-04-2023

The solution:

RightClick QB64pe desktop shortcut properties -> Advanced -> checkbox run as admin.

Most simple fix.

Erik.

https://learn.microsoft.com/en-us/windows/win32/secbp/running-with-special-privileges


RE: DATE$ function - eoredson - 10-05-2023

There may be a difference between SetLocalTime and SetSystemTime where the latter is UTC.

In control panel the date/time setting for internet clock will autoset the realtime anyway independent of what you set it for.

Erik.


RE: DATE$ function - SpriggsySpriggs - 10-05-2023

I've got code somewhere to make a program launch itself as admin. If I find it, I'll send it your way, eoredson.

EDIT: Looks like I found it

Of course, you'll have to accept the UAC prompt.

Code: (Select All)
Declare Dynamic Library "Shell32"
    Function IsUserAnAdmin& ()
    Sub ShellExecute Alias "ShellExecuteA" (ByVal hwnd As _Offset, lpOperation As String, lpFile As String, lpParameters As String, Byval lpDirectory As _Offset, Byval nShowCmd As Long)
End Declare

Sub SelfElevate
    If IsUserAnAdmin = 0 Then
        ShellExecute 0, "runas" + Chr$(0), Command$(0) + Chr$(0), Command$ + Chr$(0), 0, 5
        System
    End If
End Sub



RE: DATE$ function - eoredson - 10-06-2023

Heh.. I tried this:

Code: (Select All)
Declare Dynamic Library "Shell32"
  Function IsUserAnAdmin& ()
  Sub ShellExecute Alias "ShellExecuteA" (ByVal hwnd As _Offset, lpOperation As String, lpFile As String, lpParameters As String, Byval lpDirectory As _Offset, Byval nShowCmd As Long)
End Declare

Call SelfElevate
Print "more:";
Do
  If Len(InKey$) Then Exit Do
Loop
End

Sub SelfElevate
  Print "admin:"; IsUserAnAdmin
  'If IsUserAnAdmin = 0 Then
  ShellExecute 0, "runas" + Chr$(0), Command$(0) + Chr$(0), Command$ + Chr$(0), 0, 5
  'System
  'End If
End Sub
And it went into a endless loop display dozens of x32 shell windows and had to be forced to reboot.


RE: DATE$ function - SpriggsySpriggs - 10-06-2023

Yeah. You have to leave the code as is. The `System` call is important. As is the `IsUserAnAdmin` check.


RE: DATE$ function - eoredson - 10-06-2023

I removed the comment from 'System and it went into an endless loop anyway.

If IsUserAnAdmin check when 0 going to do the same thing?

Erik.


RE: DATE$ function - SpriggsySpriggs - 10-06-2023

It shouldn't do that. I've never seen it constantly loop on just that alone because it should report zero for normal user and nonzero for admin. If you cancel the UAC prompt, it is just going to close out anyways because the next statement is `System`. I've never had any issues using it, though. It (`SelfElevate`) is a big part of my registry library. But for future reference, leave the function as I provided. It was written this way for a reason.


RE: DATE$ function - eoredson - 10-06-2023

I have QB64pe with admin and QB64 without and all I can say is that the following code works:

Code: (Select All)
Rem Admin.bas forces user to become admin.
Declare Dynamic Library "Shell32"
  Function IsUserAnAdmin& ()
  Sub ShellExecute Alias "ShellExecuteA" (ByVal hwnd As _Offset, lpOperation As String, lpFile As String, lpParameters As String, Byval lpDirectory As _Offset, Byval nShowCmd As Long)
End Declare
If IsUserAnAdmin = 0 Then
  Color 15
  Print "User is not admin. Press key:"
  While InKey$ = "": Wend
  Color 12
  Print "Force user to admin. Press key:"
  While InKey$ = "": Wend
  Call SelfElevate
End If
Color 14
Print "User should now be admin."
Color 15
Print "more:";
Do
  X$ = InKey$
  If Len(X$) Then
      Print
      If X$ = Chr$(27) Then
        Exit Do
      End If
      If IsUserAnAdmin Then
        Color 15
        Print "User is admin."
      Else
        Color 15
        Print "User is not admin."
      End If
      Color 15
      Print "more:";
  End If
Loop
Color 7
End

Sub SelfElevate
  ShellExecute 0, "runas" + Chr$(0), Command$(0) + Chr$(0), Command$ + Chr$(0), 0, 5
  System
End Sub