@tiho999 I am confused, what two programs? When you do a RunAsWait, you remove the need to do this line as you have it above:
Run ('C:\Windows\System32\runas.exe /profile /user:' & $sDomain & $sUsername & ' "CMD /C \"' & $RunCommand & '\""')
So, based on what you have written above (unless there is more you did not include), your 11 lines of code:
Local $sUsername = "username"
Local $sPassword = "password"
Local $sDomain = "domain" & "\"
Local $RunCommand = "cmd.exe"
Run ('C:\Windows\System32\runas.exe /profile /user:' & $sDomain & $sUsername & ' "CMD /C \"' & $RunCommand & '\""')
WinWait ("C:\Windows\System32\runas.exe")
send ($sPassword & '{ENTER}')
sleep(1000)
send ("\\network1\App1\Run_App1.exe" & ' {ENTER}')
sleep(1000)
Winclose ("CMD /C")
...could be reduced to:
RunAsWait("username", "domain", "password", $RUN_LOGON_NOPROFILE, "\\network1\app1\Run_app1.exe", "<workingdir>", @SW_HIDE)
Or, if you do not want to embed username and password in the script:
$username = InputBox("Input UserName", "Please type in UserName")
$password = InputBox("Password", "Please type in Password", "", "*")
RunAsWait($username, "mydomain.com", $password, $RUN_LOGON_NOPROFILE, "\\network1\app1\Run_app1.exe", "<workingdir>", @SW_HIDE)
Again, if it works for you as written great. Just pointing out a better way to do it, which will be much easier to maintain going forward.