?
Solved

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

Posted on 2017-12-07
6
Low Priority
?
41 Views
Last Modified: 2017-12-07
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)
0
Comment
Question by:Aryabhatta M
6 Comments
 

Author Comment

by:Aryabhatta M
ID: 42395290
wsh.Run "http://localhost:"&port&"/MyWebApplication"  worked. Any seasoned programmer can suggest other code too if I have written more LOC unnecessarily.
0
 
LVL 14

Expert Comment

by:Máté Farkas
ID: 42395345
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
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 42395375
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Expert Comment

by:ste5an
ID: 42395446
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
 

Author Comment

by:Aryabhatta M
ID: 42395641
No there were more in the VBS thats why vbs was needed, particularly for refreshing browser.
0
 

Author Closing Comment

by:Aryabhatta M
ID: 42395647
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Join & Write a Comment

This article describes a serious pitfall that can happen when deleting shapes using VBA.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 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