Sign in to follow this  
Followers 0
super1337

Pass command line parameters to ShellExecute \ Runas

2 posts in this topic

I am trying to run an application that requires UAC to elevate permissions with command line parameters...

I tried the following:

If Not IsAdmin() Then
    Global $CmdArgList

    For $i = 1 To $cmdLine[0]
        $CmdArgList = $CmdArgList & ' ' & $cmdLine[$i]
    Next

    ShellExecute(@AutoItExe & $CmdArgList, "", "", "runas")
    ProcessClose(@AutoItPID)
    Exit
EndIf

It passes all the command line parameters to shell execute so that when it runs as admin, it still has the initial parameters.

Unfortunately this does not work as it complains that Windows cannot find the exe file. Apparently it doesn't like command line parameters being passed to it.

Is there a correct way to do something like this?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I just found the answer... whoops.

There is a command line option for Shell execute. The following fix works:

If Not IsAdmin() Then
    Global $CmdArgList

    For $i = 1 To $cmdLine[0]
        $CmdArgList = $CmdArgList & ' ' & $cmdLine[$i]
    Next

    ShellExecute(@AutoItExe, $CmdArgList, "", "runas")
    ProcessClose(@AutoItPID)
    Exit
EndIf
Edited by super1337

Share this post


Link to post
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
Sign in to follow this  
Followers 0