Jump to content

Using Run Command with Elevated Permissions


Recommended Posts

Is there a way to use the Run command to start an external program with Elevated permissions?

I figured out how to do this with ShellExecute by passing the "runas" verb into the function, however, I cannot find documentation for similiar functionality for the Run function.

I need to use run instead of ShellExecute in order to be able to retrieve the process id and access the stdin and stdout of the program being executed.

Link to comment
Share on other sites

I saw that command, but if used will that allow Administrative tasks to be performed?

In other words I am already running the script logged in as a user that is an Administrator, however, I need to send commands to @ComSpec and need ComSpec started with elevated permissions, as if "Run As Administrator" was clicked from the context menu when starting the program.

Link to comment
Share on other sites

OK,

so I tried doing

Local $pid=RunAs("Administrator",@ComputerName,"mypassword",0,@ComSpec,"",@SW_SHOW)

ProcessWaitClose($pid)

The resultant window does not have elevated permissions. When I attempt to execute "net user testuser test /add" it throws an access denied at the command prompt that is generated.

Link to comment
Share on other sites

OK...

The script does what i want it to do, however, I am a bit confused on the behavior of the run command and the various ways it can be used.

Currently, my script looks as follows:

Local $pid=RunAs("Administrator",@ComputerName,"mypassword",0,@ComSpec,"",@SW_SHOW,$STDIN_CHILD)

StdInWrite($pid,"net user test Test1 /add" & @CRLF)
StdInWrite($pid, "exit" & @CRLF)

ProcessWaitClose($pid)

Everything works as expected and the user is created. However, a seperate window with the command prompt is not created and rather the output is a part of the AutoIT Editor at the bottom of the window. I was under the impression that since I did not specify $STDOUT_CHILD that the output would occur as normal in a seperate window.

For this particular example this does not matter that much, however, I am trying to learn the various ways of using run and what the various options are.

Link to comment
Share on other sites

The Scite output pane is like a command window console in itself. You can go to the output pane and type cmd /? and it give you a cmd prompt. It may capture the stream output and can be an obstacle sometimes for stdin if it steals the stream. Try testing without Scite for a comparison. Seeing the result maybe differcult though unless you use stdout and write to file or similar as a log.

The stdio stream may not show in the command window that may display as you have redirected the stream pipe. More testing done by you may help you understand how RunAs() works.

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...