Jump to content
Sign in to follow this  
dcapone

Using Run Command with Elevated Permissions

Recommended Posts

dcapone

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.

Share this post


Link to post
Share on other sites
MHz

Sure. Actually you mentioned the magic work in your post. Look at the RunAs() function in the help file. :idea:

Share this post


Link to post
Share on other sites
dcapone

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.

Share this post


Link to post
Share on other sites
MHz

RunAs() will cause @Comspec to inherit elevated permissions. Just give a try to find out for yourself.

Share this post


Link to post
Share on other sites
dcapone

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.

Share this post


Link to post
Share on other sites
dcapone

Ok, scratch that...I was trying to use a second administrator account, this apparently only works with the actual "Administrator" account.

Share this post


Link to post
Share on other sites
dcapone

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.

Share this post


Link to post
Share on other sites
MHz

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.

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.