//flex table opened by JP

Click to See Complete Forum and Search --> : "runas" command line without manually typing a password


tantone
01-06-2004, 02:21 PM
I found a handy VB script today that enabled us to automate the install of a few different apps without our intervention, or even the user having to type in the password of the account being used for the install. When I find the site I got it from again, I'll post back with the person/org where the credit belongs. I didn't write this.
(I didn't want the user to have to do anything because, as well all know, someone with a 180 IQ drops to around 30 as soon as you give them user-level access for some reason)

Anyway, using a batch file, just call the code below using the proper paramaters and BAM! All done!

'RunAs Helper
'Syntax: runas.vbs <username> <password> <command>
'
set args=wscript.arguments
username = args(0)
pass = args(1)

'Get the command arguments
for i=2 to args.count - 1
command = command & args.item(i) & " "
Next

'Used for testing
'wscript.echo "runas.exe /user:" & username & " """ & command & """"
set shell=wscript.createobject("Wscript.shell")

'Run runas.exe
shell.run "runas.exe /user:" & username & " """ & command & """"

'Wait for runas.exe to load, this time could be shorter, but is set to 1000 to be safe
wscript.sleep(1000)

'Send the password and hit enter
shell.sendkeys pass & "{ENTER}"

'end of script