10-06-2023, 03:43 AM
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