User Tools

Site Tools


microsoft:scripting:vbscript:snippets:winhttp

Check for availability ncsi.txt

strURL = "http://www.msftncsi.com/ncsi.txt"

Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
'Disable redirects, option 6.
objWinHttp.Option(6) = False
objWinHttp.Open "GET", strURL
objWinHttp.Send

strStatus = objWinHttp.Status
WScript.Echo strStatus
strResponse = objWinHttp.ResponseText
WScript.Echo strResponse

Select Case objWinHttp.Status
Case 200
	If InStr(strResponse, "Microsoft NCSI") > 0 Then
		WScript.Echo "Y E S"
	End If
Case 301
	WScript.Echo "Redirect"
Case 302
	WScript.Echo "Redirect"
Case Else
	'Error
End Select

Sources:
Neil Obremski's Stuff - WinHttp.WinHttpRequest.5.1
808.dk - VBScript WinHttp.WinHttpRequest.5.1 example with error handling

microsoft/scripting/vbscript/snippets/winhttp.txt · Last modified: 2012/02/24 21:27 by bas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki