Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runas Password in Batchfile

i want to run a batchfile with a runas command in it. Is it possible to link the password in Batch file? For example: runas /profile /user\domain PASSWORD thanks in advance for your answers

like image 751
lucas220700 Avatar asked Oct 16 '25 05:10

lucas220700


2 Answers

An Alternate Solution

It looks as though runas does not allow what you want (without severely compromising security... see below). However, there is a third-party utility called PsExec which does allow this. From the Sysinternals PsExec page:

Usage: psexec [\\computer[,computer2[,...] | @file\]][-u user [-p psswd][-n s]
              [-r servicename][-h][-l][-s|-e][-x][-i [session]]
              [-c executable [-f|-v]][-w directory][-d]
              [-<priority>][-a n,n,...] cmd [arguments]

(Note: the idea to use PsExec came from Lauren7060's answer to this question on Spiceworks).

So, something like:

psexec -u MYUSER -p MYPASSWORD MYBATCH.BAT

should do what you want.


What Doesn't Work

As you found, runas normally prompts the user to enter the password. Interestingly, you can either pipe data into runas:

echo password | runas ...

or redirect input from a file:

runas ... < PASSWORD.TXT

and runas will not prompt for a password. However, I could not get runas to accept the password as valid, however I formatted the data. In the latter case (redirecting from a file), I tried both with and without a line-ending, but neither worked. My guess is that the pipe/redirect is enough to stop runas prompting for a password, but that it doesn't really read anything from stdin. This is partially supported by this article on the Tech Torials website that describes a method where you can use runas without it prompting for a password, but only if you set the account's password to an empty string.

like image 105
TripeHound Avatar answered Oct 18 '25 04:10

TripeHound


I have also finding the way how to do this.But unfortunately i cant find any way how to do this on internet.Then i discovered(from own) one way from which you can do it without using any third party software.You can do this by using batch scripting and vbs. First I have created a vbs file to send password to command prompt and press enter automatically.I have pause script for 1s so that password can be entered after running runas command. Simply Create a file like this:-

::Creating vbs file to give password to runas command:-

 echo Set x=CreateObject("wscript.shell")>C:\users\%username%\Desktop\pass.vbs
        echo wscript.sleep 1000>>C:\users\%username%\Desktop\pass.vbs
        echo x.sendkeys "<password of user>">>C:\users\%username%\Desktop\pass.vbs
        echo x.sendkeys "{enter}">>C:\users\%username%\Desktop\pass.vbs
        start C:\users\%username%\Desktop\pass.vbs
        runas /user:<Username for which you want> "<File that you want to run>"
like image 33
SHUBHAM KUMAR SINGH Avatar answered Oct 18 '25 04:10

SHUBHAM KUMAR SINGH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!