VB.NET Call executable with parameters in VB Script

Posted on 2007-07-20
Last Modified: 2008-01-09
I have the following code, plink is is an executable. I am running this code from the same directory as the executable. When I am testing the code it does not seem to be working. Any ideas why this might be, all of the variables are being assigned correctly. If I type the command directly into a command prompt it works. Any ideas why this isnt working, also is there a way to get the output that the executable is sending out and print it wo screen?

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("cmd /c plink '" & LoadBalancer & "' -l '" & Username & "' -pw '" & Password & "' bigpipe node '" & RebootComputer & "' down")
Question by:Benjamin297
    LVL 31

    Expert Comment

    execute the script that u only see the command in a msgbox!
    Then u can verify that's all right!

    msgbox "cmd /c plink '" & LoadBalancer & "' -l '" & Username & "' -pw '" & Password & "' bigpipe node '" & RebootComputer & "' down")
    LVL 65

    Accepted Solution

    Hi, you can try replacing your single quotes in the command with the double-quote character, which you "double-up" in VBScript to represent one literal quote inside a string.
    For example:
    strString = "test string here"
    outputs: test string here
    strString = "test ""string"" here"
    output: test "string" here

    So, you can try:
    objShell.Exec("cmd /c plink """ & LoadBalancer & """ -l """ & Username & """ -pw """ & Password & """ bigpipe node """ & RebootComputer & """ down")

    And also, instead of MsgBox, I tend to use an InputBox so you can just copy and paste the exact text into a command line:
    strCommand = "cmd /c plink """ & LoadBalancer & """ -l """ & Username & """ -pw """ & Password & """ bigpipe node """ & RebootComputer & """ down"
    strCommand = InputBox("Prompt", "Title", strCommand)
    Set objExec = objShell.Exec(strCommand)


    LVL 31

    Expert Comment

    or try the vbscript function: Chr(34)  
    this makes " too

    Try also:
    objShell.Run not Exec

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now