Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open url from script on Windows Server 2008

I want to write a script that loads a url (eg. http://google.com) automatically. But I don't want to install any 3rd party libraries or programs to the server. what's the easiest way to do this?

I just my options are batch script, vb script or powershell right?

like image 346
Janie Avatar asked Oct 16 '10 00:10

Janie


3 Answers

FYI from PowerShell, if you want to retrieve the contents of the URL you can do this;

$page = (new-object net.webclient).DownloadString("http://www.bing.com")
$page # writes the contents to the console

If you just want to open it in a browser:

Start-Process http://www.bing.com

Or using the start alias

start http://www.bing.com

Start-Process is new in PowerShell 2.0.

like image 91
Keith Hill Avatar answered Nov 20 '22 14:11

Keith Hill


The beauty of Powershell is it has so many ways to do something.

This is my Powershell 2.0 example code - consisting of a Pause function to allow the site to open. It uses Internet Explorer as the browser. In this case - IE is a better browser than the others because it integrates with Powershell through a verbose API.

$url = "http://www.google.com/"
$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate($url)

There are many different functions attached to this object. I recommend loading up the Powershell command line, typing in the above code, and checking what other functions this object has. Type $ie. and pressing TAB iterates through all the methods of this library.

The more I learn of Powershell, the more exciting it becomes. There is nothing it cannot do on Windows.

like image 33
csharpforevermore Avatar answered Nov 20 '22 13:11

csharpforevermore


you can use vbscript

url="http://somewhere.com"
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
objHTTP.Open "GET", url, False
objHTTP.Send
wscript.Echo objHTTP.ResponseText
objFile.Close
like image 1
ghostdog74 Avatar answered Nov 20 '22 15:11

ghostdog74