[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

How to pass URL parameters to VBS Script File

I have a VBS Script that accepts parameters from the command line.  For example, the script will retrieve record 1011.  This works on the command line.:
c:\temp\myscript.vbs 1011

Open in new window

Now to take it a step further, my program sends an email to a user with a hyperlink which will run the script, but when I try to pass a record number in the hyperlink, I get nothing no parameters.

This will work from the Run command: "file:///c:\temp\myscript.vbs" 1011
I have tried variations of the hyperlink with no success:
<a href='"file:///c:\temp\myscript.vbs" 1011'>Test</a>
<a href='"file:///c:/temp/myscript.vbs" 1011'>Test</a>
<a href="'file:///c:\temp\myscript.vbs' 1011">Test</a>
<a href='%22file:///c:\temp\myscript.vbs%22%201011'>Test</a>

Any suggestions?
0
jekautz
Asked:
jekautz
  • 6
  • 6
2 Solutions
 
WalkaboutTiggerCommented:
Have you tried
<a href='file:///c:\temp\myscript.vbs?1011'>Test</a>

Open in new window

0
 
jekautzAuthor Commented:
I passed this into the email and it opens the script, but I get no parameter.
<a href='file:///c:\temp\myscript.vbs?1011'>Test</a>

Open in new window

Here is my VBS code that retrieves the parameters.  The two msgbox lines return 0 records and no recNum.
Sub getParam(recNum)
	' Store the arguments in a variable:
	Set objArgs = Wscript.Arguments
	wscript.echo objargs.count	
	
	If objArgs.Count > 0 Then
		recNum = objArgs(0)
	End If
        msgbox objargs.count
        msgbox recNum
End Sub

Open in new window

0
 
WalkaboutTiggerCommented:
Okay, fine!

If you're willing, try this:

<a href="#" onclick='new ActiveXObject("wscript.shell")_
          .Run("\"\\\\server\\directory\\scriptname.vbs\" Parameter")'>JScript</a>
<br>
<a href="#" onclick='vbscript:createobject("wscript.shell")_
                    .Run """\\server\directory\scriptname.vbs"" Parameter"'>VBScript</a>

Open in new window


And, of course, replace Parameter with your parameter of 1011.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jekautzAuthor Commented:
Sorry, but this didn't work either.  I found this post that explains everything I have gone through and will likely follow his lead on a Plan B solution.
after not getting any suitable responses and after continuing my research for this without success, I will temporarily conclude that what I am looking for is not possible. If the reasons for this not being possible concern security, then I am completely puzzled as to why running an exe without parameters is allowed and therefore considered LESS harmful than running an exe with parameters. Surely, an exe does not require parameters to be harmful. If anyone would care to elaborate on this, it would be educational for me, thank you. Nevertheless, I have thought of an alternative to my problem, which is not as elegant as would otherwise be stating parameters in href, but it serves my purpose. Because our app is run from a network drive, I have changed it so that it creates user-specific cmd files on the network drive and the hyperlink in the email it creates points to these cmd instead of the exe. That way, the cmd files contains the call to the exe with the correct parameters and as the cmd files are very light and quickly written, this is OK. I am closing this as "answered", but it is not. Thanks for taking your time to read.

Leo
stackoverflow.com
0
 
WalkaboutTiggerCommented:
Instead of an HTTP or HTTPS URI, have you tried this construct:

vbsfile://c:\PathToScript\scriptname.vbs%20%22Parameter%22

?

Look in the registry of one of your workstations in HKey Classes Root and search for VBSFILE
Note the Shell\Open\Command Default value
Maybe this is the right direction?
0
 
jekautzAuthor Commented:
The Shell\Open\Command is %SystemRoot%\System32\WScript.exe "%1" %*

I can get the hyperlink to successfully run wscript.exe and even myscript.vbs, but it all fails when I tried to add a parameter.  If I were to use wscript.exe then I would need tell it which script to open--which would be another parameter.  I could not get that to work either.

I have tried many variations of
"script.vbs" param
"script.vbs" "param"
script.vbs "param"
wscript.exe script.vbs param

I've tried double and single quotes and even tried replacing special characters with their URL Encoding Reference counterparts.  In all cases, when a parameter is added one of two things happen.  1) Nothing. I click the link and nothing happens.  2) a Windows dialog says it cannot find the file "c:\folder\script.vbs%20parameter". The parameter is always passed as part of the filename.

Trying vbsfile://c:\script.vbs was a good idea, but it would ask which program I want to open it with and even though I would choose the Windows Scripting Host program, it never led anywhere.
0
 
WalkaboutTiggerCommented:
In the latest variant, did you try placing the question mark between the script name and the parameter?

Have you tried this sort of construct?

<HTML>
  <HEAD>
    <SCRIPT LANGUAGE="VBScript">
      Sub LaunchProcess()
        Dim Shell
        Set Shell = CreateObject("Wscript.Shell")
        Shell.Run "cscript c:\scriptname.vbs Parameter1 Parameter2",1
        Set Shell = Nothing
      End Sub
    </SCRIPT>
  </HEAD>
  <BODY ONLOAD=LaunchProcess()>
  <BODY>
</HTML>

Open in new window

0
 
jekautzAuthor Commented:
I put more effort into that construct, but it never worked.  It seems that Outlook doesn't allow the onclick in <body> or <a> or <p>.  

Here was the output from my code.
<HTML><HEAD><SCRIPT LANGUAGE="VBScript">
Sub LaunchProcess()
Dim Shell
Set Shell = CreateObject("Wscript.Shell")
Shell.Run "cscript c:\temp\myscript.vbs", 1
Set Shell = Nothing
End Sub
</SCRIPT></HEAD><BODY><p onclick="LaunchProcess()">Test.</p><BODY></HTML>

Open in new window

0
 
WalkaboutTiggerCommented:
Have you considered instead of using a conventional VBS, publishing an HTA on a webserver, encapsulating your VBS within the HTA, and passing the HTA a value using conventional parameter notation such as:
<a href="http://intranet.company.com/hta/myscript.hta?value=1101">Test with Value parameter set to 1101</a>

Open in new window

?
0
 
jekautzAuthor Commented:
You are full of good ideas, and I think this one has the best chance of working.  However, I won't be able to get to this until tomorrow or Monday.  But I will post my results here.
0
 
WalkaboutTiggerCommented:
Some people can think outside of the box.  I often look around and ask, "What box?"
0
 
jekautzAuthor Commented:
Solution!  Thank you for sticking around WalkaboutTigger.

With WalkaboutTigger's examples, you can email a hyperlink pointing to http://server/some.hta?value=parameter1 which can run a shell to open an executable with parameters.  The only downside to this solution is that browsers prefer to download the HTA as a file.  The extra steps of downloading/locating/running the HTA with additional security dialogs could disconnect some users, but this is a workable solution to the problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now