INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Feedback
"...This was the ONLY place that I could find information that I could use to resolve the problem. So thanks once again to member TomSark and the SQL forum!..."
Geography
Where in the world do Tek-Tips members come from?
|
Applications
|
how can I enter the 'runas' password automaticaly?
Posted: 13 Nov 02 (Edited 14 Nov 02)
|
This answer has been taken from:-
http://itresources.brainbuzz.com/TechLibrary/GetHtml.asp?ID=1199&CatID=295
Full credit goes to the orginal author.
It took me several weeks of searching before I found this and it surprised me that no one had posted something similar so here it is.
-----------
Runas Replacement
RUNAS in Windows 2000 is nice, but not very script friendly. Unlike SU from the NT Resource Kit, you can't pass a password. Here is an alternative.
You can use the following script to execute a command via RUNAS. You might find this helpful for yourself, or run it from a batch file (although the password will be in clear text). Another alternative is to hardcode the command, username and password in the script, then use the Script Encoder (download from http://msdn.microsoft.com/scripting) to encode it. You run the script the same way, the file will just have a different extension: cscript vbrunas.vbe. Then if you have repeatable admin tasks you or your users, just execute the script.
'Start of Script 'VBRUNAS.VBS 'v1.2 March 2001 'Jeffery Hicks 'jhicks@quilogy.com http://www.quilogy.com 'USAGE: cscript|wscript VBRUNAS.VBS Username Password Command 'DESC: A RUNAS replacement to take password at a command prompt. 'NOTES: This is meant to be used for local access. If you want to run a command 'across the network as another user, you must add the /NETONLY switch to the RUNAS 'command.
' ********************************************************************************* ' * THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED AS * ' * NECESSARY TO MEET YOUR NEEDS. THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, * ' * EXPRESS, IMPLIED OR OF ANY OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS. * ' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB * ' * ENVIRONMENT. USE AT YOUR OWN RISK. * ' *********************************************************************************
On Error Resume Next dim WshShell,oArgs,FSO
set oArgs=wscript.Arguments
if InStr(oArgs(0),"?")<>0 then wscript.echo VBCRLF & "? HELP ?" & VBCRLF Usage end if
if oArgs.Count <3 then wscript.echo VBCRLF & "! Usage Error !" & VBCRLF Usage end if
sUser=oArgs(0) sPass=oArgs(1)&VBCRLF sCmd=oArgs(2)
set WshShell = CreateObject("WScript.Shell") set WshEnv = WshShell.Environment("Process") WinPath = WshEnv("SystemRoot")&"\System32\runas.exe" set FSO = CreateObject("Scripting.FileSystemObject")
if FSO.FileExists(winpath) then 'wscript.echo winpath & " " & "verified" else wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"." & VBCRLF & "You must be running Windows 2000 for this script to work." set WshShell=Nothing set WshEnv=Nothing set oArgs=Nothing set FSO=Nothing wscript.quit end if
rc=WshShell.Run("runas /user:" & sUser & " " & CHR(34) & sCmd & CHR(34), 2, FALSE) Wscript.Sleep 30 'need to give time for window to open. WshShell.AppActivate(WinPath) 'make sure we grab the right window to send password to WshShell.SendKeys sPass 'send the password to the waiting window.
set WshShell=Nothing set oArgs=Nothing set WshEnv=Nothing set FSO=Nothing
wscript.quit
'************************ '* Usage Subroutine * '************************ Sub Usage() On Error Resume Next msg="Usage: cscript|wscript vbrunas.vbs Username Password Command" & VBCRLF & VBCRLF & "You should use the full path where necessary and put long file names or commands" & VBCRLF & "with parameters in quotes" & VBCRLF & VBCRLF &"For example:" & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog e:\scripts\admin.vbs" & VBCRLF & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog " & CHR(34) &"e:\program files\scripts\admin.vbs 1stParameter 2ndParameter" & CHR(34)& VBCRLF & VBCRLF & VBCLRF & "cscript vbrunas.vbs /?|-? will display this message."
wscript.echo msg
wscript.quit
end sub 'End of Script
|
Back to VBScript FAQ Index
Back to VBScript Forum |
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close