Running a EXE with parameters from script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blazted
    New Member
    • Mar 2007
    • 17

    Running a EXE with parameters from script

    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.



    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set wshShell = WScript.CreateObject ("WSCript.shell")
    wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900"""
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

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

    Comment

    • Robbie
      New Member
      • Mar 2007
      • 180

      #3
      This is based purely on my experience with shortcuts in Windows, but I think this is wrong...
      "c:\path\file.e xe -parameters"
      ...and this is right:
      "c:\path\file.e xe" -parameters

      In other words, when you're setting that string, you need to do something like this:
      chr(34)& "c:\path\file.e xe" & 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.
      Last edited by Robbie; Feb 8 '08, 04:06 PM. Reason: Clarified what I meant

      Comment

      • blazted
        New Member
        • Mar 2007
        • 17

        #4
        Thanks for the input. i figured it out by seprating the exe from the parameters.

        Code:
        wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm -listen 5900"
        A good littl tidbit i wont forget

        Comment

        • Robbie
          New Member
          • Mar 2007
          • 180

          #5
          Originally posted by blazted
          Thanks for the input. i figured it out by seprating the exe from the parameters.

          Code:
          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%\s ystem32\notepad .exe" "c:\the correct folder\file.txt "

          Comment

          • blazted
            New Member
            • Mar 2007
            • 17

            #6
            Originally posted by blazted
            Thanks for the input. i figured it out by seprating the exe from the parameters.

            Code:
            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.
            Code:
            @echo on
            c:
            cd\
            cls
            cd "c:\Program Files\UltraVNC"
            call vncviewer.exe -dsmplugin MSRC4Plugin.dsm -listen 5900
            end
            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.

            Comment

            • blazted
              New Member
              • Mar 2007
              • 17

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

              Code:
              wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"" -dsmplugin MSRC4Plugin.dsm"
              This activated the viewer with the plug-in

              Code:
              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

              Code:
              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.

              Comment

              • blazted
                New Member
                • Mar 2007
                • 17

                #8
                Any one have any more suggestions on this?

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by blazted
                  Code:
                  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...
                  Code:
                  wshshell.run """c:\Program Files\UltraVNC\vncviewer.exe"[B]" "[/B]"-dsmplugin MSRC4Plugin.dsm"[B]"[/B] [B]""[/B]-listen 5900[B]""[/B]"

                  Comment

                  • osamashello
                    New Member
                    • Oct 2017
                    • 1

                    #10
                    thanks it helped alot

                    Comment

                    Working...