I'm trying to get a batch file to automatically enter the password into the "runas" program, but I can't get it to work. Here's my batch file so far:
echo password | runas /user:testuser c:/path/to/my/program.exe
However, I get an error saying "unknown user name or bad password". I have also tried:
runas /user:testuser c:/path/to/my/program.exe < c:/path/to/file/containing/password.txt
This comes back with the same error. Does anyone know a way to do this? What I'm trying to do eventually is get the batch file to read a username and password from a config file, and then start "program.exe" as that user.
Automatically Elevating a Batch Filebat file under the “START” label. This batch file creates a Vbscript file which then re-launches the batch file as administrator (if it's not already running under administrator privileges) using the “runas” parameter which is needed to elevate it.
Set the task up without a trigger, allow it to be manually executed in the advanced options. Actions run a program "c:\windows\system32\cmd.exe /c", with the parameter or arguments field set the path to the batch file, and start in path of where the batch file is or c:\ (doesn't matter much).
The Batch-JScript hybrid script below do what you want. Save it with .bat extension.
@if (@CodeSection == @Batch) @then
@echo off
start "" runas /user:testuser c:/path/to/my/program.exe
CScript //nologo //E:JScript "%~F0"
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys("password{ENTER}");
For further details, see this post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With