Neat little RunAs one-liners – ADHERE and ADFILE – Tales from the Crypto

Neat little RunAs one-liners – ADHERE and ADFILE

ADHERE.BAT


Short for “Admin Here”, I’ve been enjoying this little one-line batch script:


@runas /u:%1 “cmd /k cd /d %cd%”


What’s it do?


First, it’s important to note that it takes a parameter, the username that you want to run as.


It’ll open up a new CMD window – a command prompt window – in the directory that you’re currently in. This prevents you from arriving in the C:\Windows\System32 directory every time you realise that you need an administrator account to run a few commands.


ADFILE.BAT


Short for “Admin File”, here’s the obvious next step:


@runas /u:%1 “cmd /c cd /d %cd% & start %2”


Takes two parameters, the first being the user you want to runas, and the second being the file you want to run / open.


Enjoy.


[Of course, you may want to hard-code the admin user name into the batch file.  Be my guest]


[Update 7/7 – added the “/d” parameter, so you can “ADHERE” and “ADFILE” from directories on other drives.]

Leave a Reply

Your email address will not be published. Required fields are marked *