Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Declare Function GetVersion Lib "kernel32" () As Long
- Private Declare Function IsAdminMode Lib "shell32" Alias "#680" () As Long
- Private Declare Function ShellExecuteA Lib "shell32" (ByVal hWnd As Long, ByVal sOper As String, ByVal sFile As String, ByVal sPrm As String, ByVal sDir As String, ByVal lShowCmd As Long) As Long
- Function GetVerMajor() As Long
- GetVerMajor = Val(Right$(Hex$(GetVersion), 2))
- End Function
- Sub RunMeAsAdminMode()
- If (IsAdminMode = 1) Then Exit Sub
- Call ShellExecuteA(0, IIf(GetVerMajor > 5, "runas", "open"), App.EXEName & ".exe", Interaction.Command$, App.Path, 10)
- End
- End Sub
- Private Sub Form_Load()
- Call MsgBox("Administrator mode = " & CBool(IsAdminMode), vbInformation)
- Call RunMeAsAdminMode
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement