RunAs

Specifies a set of user credentials to use for all subsequent Run and RunWait commands.

RunAs , User, Password, Domain

Parameters

User

If this and the other parameters are all omitted, the RunAs feature will be turned off, which restores Run and RunWait to their default behavior. Otherwise, specify the username under which new processes will be created.

Password

If blank or omitted, it defaults to a blank password. Otherwise, specify the User's password. Note that passing blank passwords is not allowed by default, according to the OS policy "Accounts: Limit local account use of blank passwords to console logon only".

Domain

If blank or omitted, a local account will be used. Otherwise, specify User's domain. If that fails to work, try using @YourComputerName.

Remarks

If the script is running with restricted privileges due to User Account Control (UAC), any programs it launches will typically also be restricted, even if RunAs is used. To elevate a process, use Run *RunAs instead.

This command does nothing other than notify AutoHotkey to use (or not use) alternate user credentials for all subsequent Run and RunWait commands.

ErrorLevel is not changed by this command. If an invalid User, Password, and/or Domain is specified, Run and RunWait will display an error message explaining the problem (unless their UseErrorLevel option is in effect).

While the RunAs feature is in effect, Run and RunWait will not able to launch documents, URLs, or system verbs. In other words, the file to be launched must be an executable file.

The "Secondary Logon" service must be set to manual or automatic for this command to work (the OS should automatically start it upon demand if set to manual).

Run, RunWait

Examples

Opens the registry editor as administrator.

RunAs, Administrator, MyPassword
Run, RegEdit.exe
RunAs  ; Reset to normal behavior.