Hi Everyone, I have a question regarding script syntax. I have numerous
examples of how to script WMI this way, but I'm bound and determined to
figure out why my script won't compile and run properly.

Here's the command prompt way of doing what I want:

C:\>runas /user:username "SHUTDOWN -R -F -M \\VCALDISP-1l -t 5" |
J:\SUPPORT\SANUR\SANUR password

This works perfectly.

Here's one version of the script I'm working on, but no matter how I format
the cCmd var, the script errors out:

(watch out for word wrapping)

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
cCmd = "runas /user:username " & """ & "SHUTDOWN -R -F -M
\\VCALDISP-3S-VIS -t 5 " & """ & " | J:\SUPPORT\SANUR\SANUR password"
oShell.run cCmd
Set oShell = Nothing

Can anyone tell what's wrong?

Thanks.

--
William Fields
MCSD - Microsoft Visual FoxPro
MCP - Win2k Pro
US Bankruptcy Court
Phoenix, AZ

Bruce Lee was the man. Be water.

Re: Syntax help using RunAs to issue a Shutdown.exe command. by Michael

Michael
Thu Oct 07 19:50:05 CDT 2004

William Fields wrote:
> Hi Everyone, I have a question regarding script syntax. I have
> numerous examples of how to script WMI this way, but I'm bound and
> determined to figure out why my script won't compile and run properly.
>
> Here's the command prompt way of doing what I want:
>
> C:\>runas /user:username "SHUTDOWN -R -F -M \\VCALDISP-1l -t 5" |
> J:\SUPPORT\SANUR\SANUR password
>
> This works perfectly.
>
> Here's one version of the script I'm working on, but no matter how I
> format the cCmd var, the script errors out:


Where you have

... & """ & ...

you need

... & """" & ...

or
... & Chr(34) & ...


>
> (watch out for word wrapping)
>
> Dim oShell
> Set oShell = WScript.CreateObject ("WSCript.shell")
> cCmd = "runas /user:username " & """ & "SHUTDOWN -R -F -M
> \\VCALDISP-3S-VIS -t 5 " & """ & " | J:\SUPPORT\SANUR\SANUR password"
> oShell.run cCmd
> Set oShell = Nothing
>
> Can anyone tell what's wrong?
>
> Thanks.

--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US

Re: Syntax help using RunAs to issue a Shutdown.exe command. by William

William
Fri Oct 08 11:40:44 CDT 2004

Thanks Michael, almost there...

This works:

cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
\\VCALDISP-3S-VIS -t 1 " & """"

A command prompt window is opened and I am prompted for the password.

This doesn't work:

cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
\\VCALDISP-3S-VIS -t 1 " & """" & "| J:\SUPPORT\SANUR\SANUR password"

The command window flashes, and I see what looks like the RUNAS USAGE
screen, but it goes pretty quick.

Is there a way to echo/pause the command being sent to the command prompt
window so I can check the format of the command line?

Thanks.

--
William Fields
MCSD - Microsoft Visual FoxPro
MCP - Win2k Pro
US Bankruptcy Court
Phoenix, AZ

Bruce Lee was the man. Be water.


"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:eJhyBDNrEHA.1164@TK2MSFTNGP10.phx.gbl...
> William Fields wrote:
>> Hi Everyone, I have a question regarding script syntax. I have
>> numerous examples of how to script WMI this way, but I'm bound and
>> determined to figure out why my script won't compile and run properly.
>>
>> Here's the command prompt way of doing what I want:
>>
>> C:\>runas /user:username "SHUTDOWN -R -F -M \\VCALDISP-1l -t 5" |
>> J:\SUPPORT\SANUR\SANUR password
>>
>> This works perfectly.
>>
>> Here's one version of the script I'm working on, but no matter how I
>> format the cCmd var, the script errors out:
>
>
> Where you have
>
> ... & """ & ...
>
> you need
>
> ... & """" & ...
>
> or
> ... & Chr(34) & ...
>
>
>>
>> (watch out for word wrapping)
>>
>> Dim oShell
>> Set oShell = WScript.CreateObject ("WSCript.shell")
>> cCmd = "runas /user:username " & """ & "SHUTDOWN -R -F -M
>> \\VCALDISP-3S-VIS -t 5 " & """ & " | J:\SUPPORT\SANUR\SANUR password"
>> oShell.run cCmd
>> Set oShell = Nothing
>>
>> Can anyone tell what's wrong?
>>
>> Thanks.
>
> --
> Michael Harris
> Microsoft.MVP.Scripting
> Sammamish WA US



Re: Syntax help using RunAs to issue a Shutdown.exe command. by Torgeir

Torgeir
Fri Oct 08 12:13:05 CDT 2004

William Fields wrote:

> Thanks Michael, almost there...
>
> This works:
>
> cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
> \\VCALDISP-3S-VIS -t 1 " & """"
>
> A command prompt window is opened and I am prompted for the password.
>
> This doesn't work:
>
> cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
> \\VCALDISP-3S-VIS -t 1 " & """" & "| J:\SUPPORT\SANUR\SANUR password"
>
> The command window flashes, and I see what looks like the RUNAS USAGE
> screen, but it goes pretty quick.
>
> Is there a way to echo/pause the command being sent to the command prompt
> window so I can check the format of the command line?
>
> Thanks.
Hi

When using piping (|) or redirecting (<>) on the command line, you need
to use cmd.exe /c (environment variable %comspec% is best).

Here is your command line in a modified version:

cCmd = "%comspec% /c runas.exe /user:administrator ""SHUTDOWN.exe -R -F -M
\\VCALDISP-3S-VIS -t 1"" | J:\SUPPORT\SANUR\SANUR.exe password"

To keep the command prompt open, change comspec's parameter /c to /k.

Also note that

"..." & """" & "..."

is the same as

"...""..."

(as implemented in my version of cCmd above). Inside a quoted string,
use two quotes to get one effective.



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Syntax help using RunAs to issue a Shutdown.exe command. by William

William
Fri Oct 08 12:43:03 CDT 2004

Thanks guys!

Good lesson.

--
William Fields
MCSD - Microsoft Visual FoxPro
MCP - Win2k Pro
US Bankruptcy Court
Phoenix, AZ

Bruce Lee was the man. Be water.


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:uJSgpoVrEHA.2900@TK2MSFTNGP12.phx.gbl...
> William Fields wrote:
>
>> Thanks Michael, almost there...
>>
>> This works:
>>
>> cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
>> \\VCALDISP-3S-VIS -t 1 " & """"
>>
>> A command prompt window is opened and I am prompted for the password.
>>
>> This doesn't work:
>>
>> cCmd = "runas /user:administrator " & """" & "SHUTDOWN -R -F -M
>> \\VCALDISP-3S-VIS -t 1 " & """" & "| J:\SUPPORT\SANUR\SANUR password"
>>
>> The command window flashes, and I see what looks like the RUNAS USAGE
>> screen, but it goes pretty quick.
>>
>> Is there a way to echo/pause the command being sent to the command prompt
>> window so I can check the format of the command line?
>>
>> Thanks.
> Hi
>
> When using piping (|) or redirecting (<>) on the command line, you need
> to use cmd.exe /c (environment variable %comspec% is best).
>
> Here is your command line in a modified version:
>
> cCmd = "%comspec% /c runas.exe /user:administrator ""SHUTDOWN.exe -R -F -M
> \\VCALDISP-3S-VIS -t 1"" | J:\SUPPORT\SANUR\SANUR.exe password"
>
> To keep the command prompt open, change comspec's parameter /c to /k.
>
> Also note that
>
> "..." & """" & "..."
>
> is the same as
>
> "...""..."
>
> (as implemented in my version of cCmd above). Inside a quoted string,
> use two quotes to get one effective.
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx