[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Running a command using vbscript with muliple quotes

Hello,

I'm trying to run this simple command using vbscript.

psshutdown.exe -r -m "System is shutting down"

I'm having trouble in Vbscript using the WshShell.Run method because of the additonal quotation marks needed.

I've played around with Chr(34) but still can't get it to work at all.

Any ideas on how I can take the following code and make it work. The -m switch is for the shutdown message. The shutdown message has to be in quotes too.

Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "PsShutdown.exe -r -m "System is shutting down now""

Thanks
0
hpops
Asked:
hpops
2 Solutions
 
hongjunCommented:
Try this

Dim myCommand

myCommand = "PsShutdown.exe -r -m ""System is shutting down now"""
wshShell.Run myCommand
0
 
hongjunCommented:
Use 2 quotes to represent 1 quote
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So this doesnt' work?

    wshShell.Run "PsShutdown.exe -r -m " & Chr(34) & "System is shutting down now" & Chr(34)
0
 
Leo EikelmanCommented:
Try

Dim sysShutdown as String

sysShutdown = "System is shutting down now"

wshShell.Run "PsShutdown.exe -r -m " & sysShutdown

0
 
hpopsAuthor Commented:
Thanks to both of you. Both methods work and give me a choice on which direction to take. I like both solutions but for my needs this time around Idle Mind's solution fits me a bit better. I like hongjun's method too because it will come in handy for another project I'm working on.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now