Scott V
Scott V

Reputation: 25

Open Web Page from VB Script using Windows Auth

I have an ASP app. setup using Windows Authentication that I can open from IE without being prompted for credentials, but when I try to open the same ASP app. from a VB Script I get a 401 - not authorized error.

How do I get the VB Script to open the app without supplying credentials?

VB Script:

Dim srvHTTP
set srvHTTP = CreateObject("MSXML2.ServerXMLHttp.3.0")
srvHTTP.open "GET", "http://myserver/sample.aspx", false
srvHTTP.send
WScript.Echo("Status: " & srvHTTP.status)

Upvotes: 2

Views: 1757

Answers (1)

Bond
Bond

Reputation: 16311

Try using the WinHttpRequest object instead. It allows you to specify the logon policy. The following example may work for you.

Const AutoLogonPolicy_Always = 0

Dim objWinHttp
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
objWinHttp.Open "GET", "http://myserver/sample.aspx", False
objWinHttp.Send

You may also need to configure your proxy to enable "keep alive" connections, since NTLM authentication requires a number of handshakes.

Upvotes: 1

Related Questions