Skip to main content David Edelstein's Blog

Use runas with credentials

Published: 2015-10-14
David Edelstein

As a security feature, the Windows command runas won’t let you include the username and password in the commandline.  This means you can’t just create a batch file with your username and password and simply run that in order to do an integrated login across domains.  Instead, runas forces you to type in your password at the prompt. 

A co-worker of mine found an interesting workaround using a script. Just put the following into a .bat file

@if (@CodeSection == @Batch) @then
@echo off
start "" runas /netonly /user:DOMAINUSER "C:PATH-TO-PROGRAM"
CScript //nologo //E:JScript "%~F0"
goto :EOF

Replace DOMAIN, USER, PASSWORD and PATH-TO-PROGRAM as appropriate for your application.

Remember! Runas has this security feature for a reason. Doing the above is probably not a good idea.