AutoHotkey: Using RunAs and RunWait

I recently stumbled into a problem while attempting to automate a process that required domain credentials while logged in as a local user. I could use RunWait to run the program, but it would fail unless I was a domain user. When I attempted to use RunAs and RunWait together, I was met with an error that was “possibly related to RunAs.” I mean, who knows for sure what it was related to, am I right? It looked like this:

Don't tell anyone my credentials!

I am not sure whether this is an oversight, a bug, or done by design, but in any case, it wasn’t gonna work out for me. The workaround here is actually quite simple: Create a .bat file that includes the command you want to run (notepad.exe, in the above example) and then a command to exit the command prompt. RunWait the resulting .bat as your user of choice. Furthermore, if you hide the command prompt, it is perfectly seamless.

I ended up supplying the code to create the .bat from within my script, then deleting the resulting file when it was done. The final result looked something like this:

commands=
(
notepad.exe
exit
)
FileAppend, %commands%, Run.bat
RunAs, realUser, realPassword, realDomain
RunWait, Run.bat,,hide
RunAs
FileDelete, Run.bat

A little bit more trouble than it probably should be, but hopefully this will suit your needs if you run into this problem. Let me know if you have any better ideas.

5 thoughts on “AutoHotkey: Using RunAs and RunWait

  1. Vince Post author

    You’re going to want Receiver v3.2 Enterprise, which comes with the web plugin. Later versions got rid of this thing called the QuickConnect API that Imprivata uses for VDA and unfortunately later versions than that will break the automation process.

    Reply
        1. vince

          Just a shot in the dark — have you ever seen the issue when ‘tapping’ over to another PC (roaming) the session hangs at negoiating capibilies and tossesthe user out?

          Reply

Leave a Reply

Your email address will not be published. Required fields are marked *