Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to construct a Hyperlink to Launch a Batch File with Parameters?  (Read 24371 times)

0 Members and 1 Guest are viewing this topic.

exotic

    Topic Starter


    Greenhorn

    • Computer: Specs
    • Experience: Beginner
    • OS: Other
    Hello!

    This is my first post - so I would first like to say what a fantastic website this has been to me - for several years. I finally had to register, since I have a problem which I think cannot be solved but would like to run it past the resident experts first....

    I need to construct a hyperlink which will launch a batch file with a parameter. It might look something like this:

    Code: [Select]
    <a target=new href="U:\PLINK.BAT SERVER09231">U:\PLINK.BAT SERVER09231</a>
    However, this fails to launch when you click it - I think due to the space before the parameter - as it gets interpreted as part of the filename.

    Any suggestions on how to achieve this, or is it impossible?

    Many thanks.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: How to construct a Hyperlink to Launch a Batch File with Parameters?
    « Reply #1 on: January 14, 2012, 10:05:07 AM »
    Hello!

    This is my first post - so I would first like to say what a fantastic website this has been to me - for several years. I finally had to register, since I have a problem which I think cannot be solved but would like to run it past the resident experts first....
    What kept you from registering to help others with their problems?

    exotic

      Topic Starter


      Greenhorn

      • Computer: Specs
      • Experience: Beginner
      • OS: Other
      Re: How to construct a Hyperlink to Launch a Batch File with Parameters?
      « Reply #2 on: January 14, 2012, 10:55:15 AM »
      What kept you from registering to help others with their problems?

      I guess when ever I came across the ComputerHope forum it was from a Google search when looking for answers to questions similar to my own, and the questions found typically were already comprehensively answered. But it was the MSDOS section http://www.computerhope.com/msdos.htm I used mostly, which never required registration.

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: How to construct a Hyperlink to Launch a Batch File with Parameters?
      « Reply #3 on: January 14, 2012, 12:36:47 PM »
      I don't think you can pass a parameter to a batch file like that from a web page and have it run.  Pretty sure it is impossible but I have been known to be wrong.

      exotic

        Topic Starter


        Greenhorn

        • Computer: Specs
        • Experience: Beginner
        • OS: Other
        Re: How to construct a Hyperlink to Launch a Batch File with Parameters?
        « Reply #4 on: January 15, 2012, 03:31:42 AM »
        Having thought about how other languages pass parameters, and PHP being the most memorable, I tried using the "?" mark as follows:

        Code: [Select]
        <a target=new href="U:\PLINK.BAT?SERVER09231">U:\PLINK.BAT?SERVER09231</a>
        This does actually launch the batch file now.

        For test purposes I have in the batch file...
        Code: [Select]
        ECHO %CMDCMDLINE%
        Quote
        %CMDCMDLINE% - expands to the original command line that invoked the Command Processor.

        ...but it shows that the parameter is not being passed across:
        Quote
        cmd /c ""U:\PLINK.BAT" "

        The space before the final quotation mark in the output suggests provision for parameters. I wonder if there are any tricks I can add just after the "?" mark, or add additional single/double quotes somewhere in the link?
        « Last Edit: January 15, 2012, 03:42:06 AM by exotic »

        exotic

          Topic Starter


          Greenhorn

          • Computer: Specs
          • Experience: Beginner
          • OS: Other
          Re: How to construct a Hyperlink to Launch a Batch File with Parameters?
          « Reply #5 on: January 15, 2012, 11:37:06 AM »
          I couldn't get anywhere with a pure MS DOS solution, so I resorted to linking to a VBScript - since VBScript has awareness of its full URL, including the parameter after the "?" mark - then call the DOS Batch script passing it the extracted parameter:

          PLINK.HTM:
          Code: [Select]
          <a href="U:\PLINK\PLINK.VBS?server=SERVER09231">U:\PLINK\PLINK.VBS?server=SERVER09231<a/>
          PLINK.VBS:
          Code: [Select]
          <script type="text/vbscript">
          Dim sURI_Query, oShell

          set oShell=CreateObject("wscript.shell")

          sURI_Query = window.location.search
          sURI_Query = Split(sURI_Query, "server=")

          oShell.CurrentDirectory = "U:\PLINKS"
          oShell.Run "PLINK.BAT " & sURI_Query(1)
          set oShell=Nothing
          </Script>

          PLINK.BAT:
          Code: [Select]
          @ECHO OFF
          ECHO Parameter is %1