Jump to content
Sign in to follow this  
super1337

Pass command line parameters to ShellExecute \ Runas

Recommended Posts

super1337

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
super1337

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.