dcapone Posted May 1, 2010 Share Posted May 1, 2010 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 More sharing options...
MHz Posted May 1, 2010 Share Posted May 1, 2010 Sure. Actually you mentioned the magic work in your post. Look at the RunAs() function in the help file. Link to comment Share on other sites More sharing options...
dcapone Posted May 1, 2010 Author Share Posted May 1, 2010 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 More sharing options...
MHz Posted May 1, 2010 Share Posted May 1, 2010 RunAs() will cause @Comspec to inherit elevated permissions. Just give a try to find out for yourself. Link to comment Share on other sites More sharing options...
dcapone Posted May 1, 2010 Author Share Posted May 1, 2010 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 More sharing options...
dcapone Posted May 1, 2010 Author Share Posted May 1, 2010 Ok, scratch that...I was trying to use a second administrator account, this apparently only works with the actual "Administrator" account. Link to comment Share on other sites More sharing options...
dcapone Posted May 1, 2010 Author Share Posted May 1, 2010 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 More sharing options...
MHz Posted May 1, 2010 Share Posted May 1, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now