shacho
asked on
Passing Parameters to a VBScript From Command Line
Is there a way to pass parameters to a vbscript from the command line?
Basically, what I'm trying to do is something like this:
C:\> C:\MyScripts\OpenHTM.vbs "http:\\www.mysite.com"
More specifically, I want to configure this shell handler to open my vbscript and pass the URL, rather than open a specific browser.
Key: HKEY_Local_Machine\Softwar e\Classes\ htmlfile\s hell\open\ command
Current Value: "C:\Program Files\Internet Explorer\iexplore.exe" -nohome
Mike
Basically, what I'm trying to do is something like this:
C:\> C:\MyScripts\OpenHTM.vbs "http:\\www.mysite.com"
More specifically, I want to configure this shell handler to open my vbscript and pass the URL, rather than open a specific browser.
Key: HKEY_Local_Machine\Softwar
Current Value: "C:\Program Files\Internet Explorer\iexplore.exe" -nohome
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What do I need to do inside the script to catch those parameters? Public variables?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Groovy. One problem. I'm not sure how to get a hold of the parameter itself. If I click on a link, currently that link is passed by HKEY_Local_Machine\Softwar e\Classes\ htmlfile\s hell\open\ command to IE by way of "C:\Program Files\Internet Explorer\iexplore.exe" -nohome. Notice that there is nothing in that command that exposes the URL that was passed. Is there a WSript object separate from NamedArguements that could catch parameter?
Mike
Mike
ASKER
Figured it out. It's Wscript.Arguments(0).
ASKER
Almost there! Here's my script:
url = wscript.arguments(0)
if instr(1, url, "acmecompany") then
set ieapp = createobject("internetexpl orer.appli cation")
ieapp.navigate url
ieapp.visible = true
set ieapp = nothing
else
set shl = wscript.createobject("wscr ipt.shell" )
shl.run """c:\program files\mozilla firefox\firefox.exe""" & url
set shl = nothing
end if
Last thing - is there a way to run this script without displaying
a shell window during execution (no echo)?
Mike
url = wscript.arguments(0)
if instr(1, url, "acmecompany") then
set ieapp = createobject("internetexpl
ieapp.navigate url
ieapp.visible = true
set ieapp = nothing
else
set shl = wscript.createobject("wscr
shl.run """c:\program files\mozilla firefox\firefox.exe""" & url
set shl = nothing
end if
Last thing - is there a way to run this script without displaying
a shell window during execution (no echo)?
Mike
Drop a comma 0 at the end:
url = wscript.arguments(0)
if instr(1, url, "acmecompany") then
set ieapp = createobject("internetexplorer.application")
ieapp.navigate url
ieapp.visible = true
set ieapp = nothing
else
set shl = wscript.createobject("wscript.shell")
shl.run """c:\program files\mozilla firefox\firefox.exe""" & url ,0 '<<<<here
set shl = nothing
end if
ASKER
Just tried it, but the window still displays. It also displays for IE links, so I don't think it's the shell command that's causing it. I am ultimately trying to have Windows pass all clicked URLs into this script for handling, rather than passing them directly to a browser, which is what it normally does. I have configured the file type OPEN action for URLs as "c:\windows\system32\cscri pt.exe" "c:\shell\openurl.vbs" %1. I'm pretty sure that's what's causing it to pop up.
...
Flash forward - just figured out that if I change "csript" to "wscript" I can prevent the console window from showing.
"c:\windows\system32\wscri pt.exe" "c:\shell\openurl.vbs" %1
Works like a charm.
...
I have been pursuing this project with a different approach, and in fact that is the solution I went with. If you're interested in seeing what I did, here's the link.
https://www.experts-exchange.com/questions/24311499/Follow-HyperLink-Event-In-Outlook.html
Mike
...
Flash forward - just figured out that if I change "csript" to "wscript" I can prevent the console window from showing.
"c:\windows\system32\wscri
Works like a charm.
...
I have been pursuing this project with a different approach, and in fact that is the solution I went with. If you're interested in seeing what I did, here's the link.
https://www.experts-exchange.com/questions/24311499/Follow-HyperLink-Event-In-Outlook.html
Mike
ASKER
If you're searching the knowledgebase, be sure to scroll to the bottom to see my follow up comments.
Use
cscript openhtm.vbs http:\\www.mysite.com
to run this...