Re: running vbscript syntax error



psang wrote:

"runas" does not support passing password as parameter, I found a
simple VBScript which will do the job. Here is the script but it keeps
saying syntax error.
Any help will be appreciated.
-----------------------------
dim wshShell
set wshShell=CreateObject("Wscript.Shell")
wshShell.Run("Runas /noprofile /user:ABCD\administrator "cscript
c:\Script\wmi-test.vbs"")
wshShell.AppActivate "Runas"
WScript.Sleep 100
wshShell.SendKeys "passwd~"

where abcd is a Machine Name
and wmi-test.vbs is a schedular job which has to run as administraor

I have no idea if this would work, but the syntax of the argument of the Run
method above is wrong. A string must be passed to the Run method. Any quotes
embedded in the string must be doubled. So, if the command is:

Runas /noprofile /user:ABCD\administrator "cscript c:\Script\wmi-test.vbs"

then the string would be (watch out for line wrapping, this is one line):


strCmd = "Runas /noprofile /user:ABCD\administrator ""cscript
c:\Script\wmi-test.vbs"""

The double quotes in the string are resolved to single quotes. So, I would
try:

wshShell.Run("Runas /noprofile /user:ABCD\administrator ""cscript
c:\Script\wmi-test.vbs""")

To troubleshoot, run a script where you define the value of strCmd as above,
then echo the value to the screen so you can see if it is correct. If there
is a syntax error, perhaps due to unbalanced quotes, you can fix it.

Wscript.Echo strCmd

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


.



Relevant Pages

  • Re: How to pass string in command line argument.
    ... > I want to pass a command argument to perl script with double quotes (" ... > just a straight string is geeting passed ...
    (perl.beginners)
  • Re: basic help to run an application from WSH
    ... The Run method requires at least one argument, which is a string. ... string values must be enclosed in quotes. ... The Run method will execute on c:\notepad.exe. ... I'm just learning vbscript for wsh and here is my first script, ...
    (microsoft.public.scripting.vbscript)
  • Re: How to pass string in command line argument.
    ... Perl Pra wrote: ... i have perl script that searches given string (the string should be passed ... The string should be sent to the script with double quotes attached to it ...
    (perl.beginners)
  • Re: How to pass string in command line argument.
    ... i have perl script that searches given string (the string should be passed ... The string should be sent to the script with double quotes attached to it ...
    (perl.beginners)
  • Re: problem using system()
    ... I have the following string: ... Global symbol "$command" requires explicit package name at ... syntax error at remote_deploy.pl line 55, ... whole string literal with double quotes. ...
    (comp.lang.perl.misc)