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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Bill PrewCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.