In VB Script (VBS) generating URL using VARIABLE value and launching in DEFAULT BROWSER, (The VBS called from Batch)

I have a batch script MyBatch.bat . It successfully calls MyVbScript.vbs by the statement -

cscript //nologo %~dp0\MyVbScript.vbs %NewPort% where NewPort is a environment variable value.
MyVbScript.vbs is getting called successfully(tested) and value of NewPort is passed to VBS successfully(tested) from Batch script.
 
But I am NOT able to generate the URL for launching in default Browser. I want to generate the URL like -
http://localhost:7006/MyWebApplication where 7006 is value of NewPort variable.

 MyVbScript.vbs contains --

Option Explicit
Dim wsh
Dim port
Dim myNum
Set wsh=WScript.CreateObject("WScript.Shell")
port = WScript.Arguments(0)
'MsgBox port//For testing
wsh.Run " "http://localhost:"&port&"/MyWebApplication" "       ' This is not working

How to generate the URL and launch it in default browser( I dont want to specify crome or mozilla and Ie because use may not have a particular browser)
Aryabhatta MAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
If you want to pass the port as a parm then the code you have is reasonable.

You could of course pass the whole URL as a parm to the VBS, but not sure if that fits your usage any better of not.

In addition, if you wanted you could pull the environment variable value in VBS rather than pass it as a parm, but if it were me I would probably stick with passing it as a parm.


»bp
0
 
Aryabhatta MAuthor Commented:
wsh.Run "http://localhost:"&port&"/MyWebApplication"  worked. Any seasoned programmer can suggest other code too if I have written more LOC unnecessarily.
0
 
Máté FarkasDatabase Developer and AdministratorCommented:
Put your expression first into a variable to be able to print what you want to execute:
URL = "http://localhost:" & port & "/MyWebApplication"
WScript.Echo URL
wsh.Run URL

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ste5anSenior DeveloperCommented:
Well, first of all: Is this the entire VBS code? Cause then I don't understand it.. why not just doing it in your batch directly using Start url?

And last but not least it is something like

Option Explicit

Dim port
Dim url
Dim wsh

port = WScript.Arguments(0)
url = "www.localhost:" & port & "/MyWebApplication" 
WScript.Echo port & "; " & url

Set wsh=WScript.CreateObject("WScript.Shell")
wsh.Run  url
Set wsh = Nothing

Open in new window


and run this while development and testing under a command line and invoke it via cscript.exe.
1
 
Aryabhatta MAuthor Commented:
No there were more in the VBS thats why vbs was needed, particularly for refreshing browser.
0
 
Aryabhatta MAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.