Link to home
Start Free TrialLog in
Avatar of Mike
MikeFlag for United States of America

asked on

Need Help Modifing a VBS Script

Greeting Experts,
I am in need of some help with existing .vbs script used to excite windows.exe program or utility. Currently I am trying to modify the following script to start windows cmd.exe utility and use the hard-coded username and password in the script its self.  But for some reason, it keeps prompting me for a password instead of using the fixed password located on Line 26. Can someone take and look at this and see what may be wrong…

'Start of Script
'RUNAS.VBS
'USAGE: cscript|wscript VBRUNAS.VBS airseaforwarder\misrshe kinkado "C:\Program Files\Microsoft Office\Office10\outlook.exe"
'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.

On Error Resume Next
dim WshShell,oArgs,FSO

sUser="HI\MikeS1"
sPass="MikeS1"
sCmd=""

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 or XP for this script to work."
set WshShell=Nothing
set WshEnv=Nothing
set oArgs=Nothing
set FSO=Nothing
wscript.quit
end if
'Use this line for remote file access and comment out the line below
'rc=WshShell.Run("runas /netonly /user:" & sUser & " " & CHR(34) & sCmd & CHR(34), 2, FALSE)

'Use this line for local file access and comment out the above line
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 runas.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 runas.vbs domain\admin luckydog e:\scripts\admin.vbs" & VBCRLF & VBCRLF &" cscript runas.vbs domain\admin luckydog " & CHR(34) &"e:\program files\scripts\admin.vbs 1stParameter 2ndParameter" & CHR(34)& VBCRLF & VBCRLF & VBCLRF & "cscript runas.vbs /?|-? will display this message."

wscript.echo msg

wscript.quit

end sub
'End of Script 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike

ASKER

That solved the problem thanks....