Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically respond to runas from batch file

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.

like image 573
user1578653 Avatar asked Apr 04 '14 14:04

user1578653


People also ask

How can I Auto elevate my batch file?

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.

How do I run a batch file with the highest privileges and no UAC?

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).


1 Answers

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

like image 77
Aacini Avatar answered Oct 08 '22 22:10

Aacini