We help IT Professionals succeed at work.

VB.NET Call executable with parameters in VB Script

Benjamin297 asked
Medium Priority
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")
Watch Question

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")
Most Valuable Expert 2012
Top Expert 2014
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)



Not the solution you were looking for? Getting a personalized solution is easy.

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

Try also:
objShell.Run not Exec
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.