Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DATE$ function
#11
(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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#12
Huh. As usual Steve, you have solved the problem for another DUH of mine.

Yes, running as admin makes it work!?

Erik.
Reply
#13
The solution:

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

Most simple fix.

Erik.

https://learn.microsoft.com/en-us/window...privileges


Attached Files
.bas   setdate.bas (Size: 3.99 KB / Downloads: 21)
.bas   settime.bas (Size: 2.86 KB / Downloads: 20)
Reply
#14
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.
Reply
#15
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
Tread on those who tread on you

Reply
#16
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.
Reply
#17
Yeah. You have to leave the code as is. The `System` call is important. As is the `IsUserAnAdmin` check.
Tread on those who tread on you

Reply
#18
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.
Reply
#19
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.
Tread on those who tread on you

Reply
#20
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
Reply




Users browsing this thread: 21 Guest(s)