Jump to content

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"

$sPassword = "XXXXXXXXXXXXXX"

EndIf

If @ComputerName = "DEVWEB" Then

$sUserName = "DevAccount"

$sPassword = "XXXXXXXXXXXXXX"

EndIf

If $sUserName = "" Then

ConsoleWrite("Error!")

Exit

EndIf

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

Link to comment
Share on other sites

  • 1 year later...

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