Need Help with a VB Script

Greeting Experts,
I am in need of some help hardcoding the following script with the username and password to open up a program in windows.  I not sure what I may be doing wrong….?? Can somebody take a look and see what you think….


'Start of Script
'RUNAS.VBS
'USAGE: cscript|wscript VBRUNAS.VBS airseaforwarder\misrshe kinkado "C:\cmd.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

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='Username'
sPass='Password'
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

MikeSecurityAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeSecurityAuthor Commented:
Just as a point of ref: I getting stuck on line 26 char 6.... not sure if that the main problem or not.
KimputerCommented:
for those 3 lines, change it to:

sUser="Username"
sPass="Password"
sCmd=""

Open in new window


Don't use this character for strings ' (single quote)
MikeSecurityAuthor Commented:
OK, I change the 3 lines to the following and added the following

sUser='HI\MikeTEst1'
sPass='MikeTest1'
sCmd=''

Open in new window


and I am still getting error message as follows below... I have been playing with it but not sure what is means.... It refers to (sCmd=''). I not for sure how this plays in
VBS Error Code Row 26 Line 6
Webinar: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. Join us in our upcoming webinar as we discuss how to best defend against these attacks!

KimputerCommented:
I said, DON'T USE single quotes. Use DOUBLE quotes instead.
I clearly said use:

sUser="Username"
sPass="Password"
sCmd=""

Open in new window


And described why, and then you adjust your code with SINGLE QUOTES again?
MikeSecurityAuthor Commented:
Ok, you are saying to replace all single (') with double quotes (") in the Script or just in the 3 lines you refer d in the post..... I understand ... Just want to make sure I am  understand you right....
KimputerCommented:
For now, only the 3 lines. Otherwise you will uncomment the supposed comments.
MikeSecurityAuthor Commented:
Ok, this is what I have so far and I am still getting the same message. Can you take a look and see what is missing .....


 
Start of Script
'RUNAS.VBS
'USAGE: cscript|wscript VBRUNAS.VBS airseaforwarder\misrshe kinkado "C:\cmd.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

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="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

KimputerCommented:
Exact error? Assuming you forgot the first single quote while copying and pasting here ('Start of Script).
MikeSecurityAuthor Commented:
Ok, I went back and adding the Single Quote and then started getting the following error message for line 24 char 17


'Start of Script
'RUNAS.VBS
'USAGE: cscript|wscript VBRUNAS.VBS airseaforwarder\misrshe kinkado "C:\cmd.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

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="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



vbs error code Line 24 Char 17
MikeSecurityAuthor Commented:
I am looking at line 17 of (sUser="HI\MikeS1")  and don't see where it can be unexpected end statement..... Can you look at the hole script and see what mistakes have been made...
KimputerCommented:
According to me, it should run. I see no errors (also ran on my computer).

Can you remove those lines, and start TYPING it as it should be (no copy & paste, really type it) and just for readability (can't imagine why the script should trip over it, but just to try it anyway):

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

See the extra spaces.
Save,  run again.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeSecurityAuthor Commented:
Thanks for the help that worked.... :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.