Jump to content

#RequireAdmin during runtime


Recommended Posts

What options might I have to give the user the option if they want to run the current script as Admin during runtime?

I haven't tested a possible option to call a 2nd script based on the fact that I wanted to keep all the code together in a single file.

Make sense?

 

 

Link to comment
Share on other sites

Posted (edited)

Thanks @Andreik !

Was looking for something like this.

If Not IsAdmin() Then
    $bSwitchAdmin = MsgBoxYesNoCancel("You're Not Admin. Would you like to switch over now?")
    If $bSwitchAdmin Then
        ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas")
        Exit
    EndIf
EndIf
MsgBox(0, @ScriptFullPath, "Admin Rights: " & (IsAdmin() = 1) & @CRLF)

Func MsgBoxYesNoCancel($message)
    Local $result = MsgBox(262144+32+3, "Message", $message) ; 262144=topmost 32=iconquestion 3=YesNoCancel
    If $result = 6 Then ; Yes button
        Return True
    ElseIf $result = 7 Then ; No button
        Return False
    Else ; Exit button or MsgBox closed
        Exit
    EndIf
EndFunc

 

Edited by NassauSky
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...