Thursday, July 28, 2011

Calling a URL from WinPE / DaRT Environment

So maybe you find a need to call a URL from a WinPE or DaRT session (yes, I know, DaRT is a modified WinPE), but without IE or a browser you find it a challenge.  Fear not.  There are options at your disposal.

Option 1 is to install a light-weight browser into your WinPE bundle, like Bart’sPE did/does.  Firefox is a fairly common choice for that, but if you can get another browser to do that you have that option.

Option 2 is to invoke the XMLHttp object via script.  You can do that with VBscript since wscript/cscript components are part of WinPE and DaRT.  The nice thing about this is with XMLhttp, you essentially have a browser but without the GUI.  You call URL's and even fetch (i.e. "scrape") the return HTML results if needed (I do that a lot and may post some examples soon).  A command-line browser, sort of.

Here’s an example of option 2 – calling an ASP page with parameters…

url = "http://myserver.domain.com/loginfo.asp?c=Workstation123&os=Windows7&ts=Enterprise32b"

On Error Resume Next
Set ohttp = CreateObject("Microsoft.XmlHttp")
oHttp.open "GET", url, False
If err.Number <> 0 Then
wscript.Echo "fail: unable to open remote URL for asset number!"
wscript.Echo "fail: error is " & err.Number & " / " & err.Description
Else
oHttp.send ""
textData = oHttp.responseText
wscript.echo "info: completed"
End If


If error-checking isn't your cup of tea (or Four Loco), you can leave off the code from line no.4 to the end.  The meat of this is lines 2 and 3 actually.  Just create the object instance and call the .open method.  That boils down to just the following...



url = "http://myserver.domain.com/loginfo.asp?c=Workstation123&os=Windows7&ts=Enterprise32b"

Set ohttp = CreateObject("Microsoft.XmlHttp")
oHttp.open "GET", url, False
Post a Comment