By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,099 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,099 IT Pros & Developers. It's quick & easy.

Running a EXE with parameters from script

P: 17
I am trying to run a exe with parameters from a VB script. I tried writing it using a bat file but it does not close the dos prompt window so I am trying to rewrite it using VB script. It works if I do not specify any parameters for the exe to run. But i need it to run with the parameters. Not sure how to get it to run with the parameters. I need it to execute the exe then close the script. Here is my script.



Expand|Select|Wrap|Line Numbers
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  4. Set wshShell = WScript.CreateObject ("WSCript.shell")
  5. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900"""
Feb 7 '08 #1
Share this Question
Share on Google+
9 Replies


Expert 5K+
P: 8,434
I have a couple of questions. I'm only familiar with VB6, not VB Script, so I apologise if the questions don't make any sense...
  • Does c:\Program Files\UltraVNC\vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900 work if you enter it yourself at the command prompt? And in the same location where your script will be issuing it?
  • Are you certain the string needs to include the extra double-quote characters? In other words, which of the should you be issuing...
    c:\Program Files\UltraVNC\vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900
    or...
    "c:\Program Files\UltraVNC\vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900"
Feb 8 '08 #2

Robbie
100+
P: 180
This is based purely on my experience with shortcuts in Windows, but I think this is wrong...
"c:\path\file.exe -parameters"
...and this is right:
"c:\path\file.exe" -parameters

In other words, when you're setting that string, you need to do something like this:
chr(34)& "c:\path\file.exe" & chr(34) & " -parameters"
(Character 34's the speech-mark).

EDIT: In other words, the quotes should only be around the program, and the parameters come afterwords by themselves, out of quotes.
Feb 8 '08 #3

P: 17
Thanks for the input. i figured it out by seprating the exe from the parameters.

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm -listen 5900"
A good littl tidbit i wont forget
Feb 8 '08 #4

Robbie
100+
P: 180
Thanks for the input. i figured it out by seprating the exe from the parameters.

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm -listen 5900"
A good littl tidbit i wont forget
Heh, glad it helped. By the way, if you need to pass a single parameter with spaces, enclose that in speech-marks too. Otherwise they'll go through as separate ones, separated by the spaces. For example, if you want to make Notepad open a file in c:\the correct folder, you'd make the string for the shell to run be this:


"%SystemRoot%\system32\notepad.exe" "c:\the correct folder\file.txt"
Feb 8 '08 #5

P: 17
Thanks for the input. i figured it out by seprating the exe from the parameters.

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm -listen 5900"
A good littl tidbit i wont forget
Actually I spoke to soon. For some reason it does not activate both command parameters only the last one. So it will activate the listen mode but it is not loading the plugin. I cannot get it to activate both listen mode and the plugin.

I first did this as a bat file but the bat file keeps the cmd window open until i turn off listen mode. Here is my bat file.
Expand|Select|Wrap|Line Numbers
  1. @echo on
  2. c:
  3. cd\
  4. cls
  5. cd "c:\Program Files\UltraVNC"
  6. call vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900
  7. end
  8. exit
Any insight on getting both parameters to run? or if you even getting the bat file to run without keeping the cmp prompt window open.
Feb 8 '08 #6

P: 17
I verified that I can get each parameter to run separately by trying to run the command with only one parameter as the argument.

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm"
This activated the viewer with the plug-in

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe""  "-listen 5900"
This activated the viewer. But when both parameters in the same quote it only will run the last parameter bypassing the first one.

I tried to separate each parameter with its own quotes but the script will not compile

Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm" "-listen 5900"
Maybe this is simply a case of me forgetting a quote somewhere.
Feb 8 '08 #7

P: 17
Any one have any more suggestions on this?
Feb 11 '08 #8

Expert 5K+
P: 8,434
Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm" "-listen 5900"
Maybe this is simply a case of me forgetting a quote somewhere.
I don't know any more about the real issue, but you are definitely missing quotes here. Try this...
Expand|Select|Wrap|Line Numbers
  1. wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" ""-dsmplugin MSRC4Plugin.dsm"" ""-listen 5900"""
Feb 12 '08 #9

P: 1
thanks it helped alot
Oct 23 '17 #10

Post your reply

Sign in to post your reply or Sign up for a free account.