Solved

How to pass URL parameters to VBS Script File

Posted on 2016-07-18
12
132 Views
Last Modified: 2016-08-01
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
Comment
Question by:jekautz
  • 6
  • 6
12 Comments
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41718012
Have you tried
<a href='file:///c:\temp\myscript.vbs?1011'>Test</a>

Open in new window

0
 
LVL 4

Author Comment

by:jekautz
ID: 41719486
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
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41721999
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
 
LVL 4

Author Comment

by:jekautz
ID: 41727885
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
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41728682
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
 
LVL 4

Author Comment

by:jekautz
ID: 41730265
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41730369
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
 
LVL 4

Assisted Solution

by:jekautz
jekautz earned 0 total points
ID: 41732194
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
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
ID: 41733388
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
 
LVL 4

Author Comment

by:jekautz
ID: 41733731
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
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41735418
Some people can think outside of the box.  I often look around and ask, "What box?"
0
 
LVL 4

Author Closing Comment

by:jekautz
ID: 41738269
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now