Advertisement
hungvb

[VB] VB6 - Run as Administrator - HungVB.Com

Sep 25th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.79 KB | None | 0 0
  1. Option Explicit
  2. Private Declare Function GetVersion Lib "kernel32" () As Long
  3. Private Declare Function IsAdminMode Lib "shell32" Alias "#680" () As Long
  4. 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
  5.  
  6.  
  7. Function GetVerMajor() As Long
  8.     GetVerMajor = Val(Right$(Hex$(GetVersion), 2))
  9. End Function
  10.  
  11. Sub RunMeAsAdminMode()
  12.     If (IsAdminMode = 1) Then Exit Sub
  13.     Call ShellExecuteA(0, IIf(GetVerMajor > 5, "runas", "open"), App.EXEName & ".exe", Interaction.Command$, App.Path, 10)
  14.     End
  15. End Sub
  16.  
  17. Private Sub Form_Load()
  18.     Call MsgBox("Administrator mode = " & CBool(IsAdminMode), vbInformation)
  19.     Call RunMeAsAdminMode
  20. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement