Jump to content
Sign in to follow this  

RunAs(Wait) reading/writing to child process IO

Recommended Posts


Hello -

I've spent considerable time searching the forums and trying different calls to RunAs and RunAsWait to accomplish what I'm looking for, but I feel like I'm missing a crucial step. My end-goal is simply this: Run a program in a console window with an account with higher-level priviledges, and have the user be able to interact with the called process as if they launched it from the console window.

Why do I want to do this? Basically because we lock down our Dev/Test environments such that developers don't do silly things like install odd binaries or make compromising configurations to Windows. The only downside is, there are some processes that require admin perms that we'd like the developers to be able to change in a controlled fashion. Which is exactly where AutoIT makes sense - I can write scripts that control exactly how the user changes system level parameters.

So my realistic example is, I want to be able to run the Deploy.cmd command with an elevated account such that it can interact with system level components like IIS, and have all the stderr & stdout displayed in the same window that the user lauched the compiled .exe generated with AutoIT.

Is this possible?

; Fill in the username and password appropriate for your system.

#include "Constants.au3"

Local $sUserName = ""

Local $sPassword = ""

; Local $sProgram = "C:\Windows\System32\cmd.exe /C C:\IT\Deploy.cmd"

Local $sProgram = "C:\Windows\System32\whoami.exe"

Local $sWorkingDir = "C:\IT\workingfiles"

If @ComputerName = "TESTWEB" Then

$sUserName = "TestAccount"



If @ComputerName = "DEVWEB" Then

$sUserName = "DevAccount"



If $sUserName = "" Then




ConsoleWrite("Starting " & $sProgram & " with the following parameters: Username: " & $sUsername & " Password: " & $sPassword)

; Run a command prompt as the other user.

RunAsWait($sUserName, @ComputerName, $sPassword, 4, $sProgram, $sWorkingDir,@SW_MAXIMIZE ,$STDERR_MERGED)

ConsoleWrite(@CRLF & "Done...")

Share this post

Link to post
Share on other sites

Did anyone else run into this problem? 

I am getting error 1326 when I use logon flag = 0 or 1, error 267 when I use logon flag 2, and error 1783 when I use logon flag 4

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