Scriptable Command Line RunAs
Just talking to a buddy of mine in the UK and he asked something kinda interesting. The client he’s working for is trying to run a command… in another user’s security context. The client is doing this from the command line and wants the whole process to be interaction free.
Windows offers a built in tool called ‘runas’. Go ahead and try this out from your command line.
runas /user:mycomputer\sampleuser notepad.exe
The command will prompt you for the user’s password then run the command as if you were that user. Hmm… this process has to be ‘interaction free’ so prompting for the password would fail this requirement.
If only we had a way to “pipe” the password in. Yup… someone on the internet has done this.
http://www.commandline.co.uk/sanur/
The resulting command is:
runas /user:mycomputer\sampleuser notepad.exe | sanur pa55words
Bam! You have a scriptable way to run a command in another context. Got to love the internet.
Side note: The developers were trying to write their own tool using .NET C# and the CreateProcessWithLogonW function. If we figure this out, I’ll fill you guys in.