Running a command using vbscript with muliple quotes

Posted on 2006-03-23
Last Modified: 2008-03-10

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

Question by:hpops
    LVL 33

    Assisted Solution

    Try this

    Dim myCommand

    myCommand = "PsShutdown.exe -r -m ""System is shutting down now"""
    wshShell.Run myCommand
    LVL 33

    Expert Comment

    Use 2 quotes to represent 1 quote
    LVL 85

    Accepted Solution

    So this doesnt' work?

        wshShell.Run "PsShutdown.exe -r -m " & Chr(34) & "System is shutting down now" & Chr(34)
    LVL 8

    Expert Comment

    by:Leo Eikelman

    Dim sysShutdown as String

    sysShutdown = "System is shutting down now"

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


    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now