To complement K J's helpful answer:
If this is about interactive convenience and it's acceptable to have to provide the password interactively once per computer (and user), consider use of runas.exe
's /savecred
option:
runas /user:nonadmin /savecred "C:\Program Files (x86)\API\Flex.exe"
This will prompt for nonadmin
's password on first invocation on a given computer for the current user, and not require providing a password in subsequent calls.
Otherwise, if installing a utility such as psexec
(shown in K J's answer) isn't an option:
You can send keystrokes to runas.exe
that simulate interactive password entry:
# Set your password here, or add it directly to the .SendKeys() argument below.
$password = 'test'
# Send the password as keystrokes, followed by Enter, then
# launch runas.exe, which should receive the keystrokes as if they
# had been typed interactively.
(New-Object -ComObject WScript.Shell).SendKeys("$password{ENTER}"); runas /user:nonadmin "C:\Program Files (x86)\API\Flex.exe"
Note: