title: 401 Unauthorised errors when attempting to download ASP page to file
body: <p><strong>Issue</strong></p>
  
  <p>Msxml2.ServerXMLHTTP keeps returning 401 - Unauthorised errors each time we attempt to read the contents of a file (ASP) from a web server.</p>
  
  <p>Source server is running IIS6, using NTLM integrated login.</p>
  
  <p>This process has been used successfully before, but only in as far as extracting XML files from external websites, not internal ones.</p>
  
  <p>The proxy settings in the registry of the server on which the script is run has also been updated to bypass the website in question, but to no avail.</p>
  
  <p>All paths identified in the VBScript have been checked and tested, and are correct.</p>
  
  <p>User running the script has correct read/write permissions for all locations referenced in the script.</p>
  
  <p><strong>Solution needed</strong></p>
  
  <p>To identify the cause of the HTTP 401 Unauthorised messages, so that the script will work as intended.</p>
  
  <p><strong>Description</strong></p>
  
  <p>Our organisation operates an intranet, where the content is replicated to servers at each of our remote sites. This ensures these sites have continued fast access to important information, documentation and data, even in the event of losing connectivity.</p>
  
  <p>We are in the middle of improving the listing and management of Forms (those pesky pieces of paper that have to be filled in for specific tasks). This involves establising a database of all our forms.</p>
  
  <p>However, as the organisation hasn't been smart enough to invest in MSSQL Server instances at each site, replication of the database and accessing it from the local SQL server isn't an option.</p>
  
  <p>To work around this, I have constructed a series of views (ASP pages) which display the required data. I then intend to use Msxml2.ServerXMLHTTP by VBScript, so I can read the resulting pages and save the output to a static file back on the server.</p>
  
  <p>From there, the existing replication process can stream these files out to the site - with users having no idea that they're looking at a static page that just happened to be generated from database output.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>' Forms - Static Page Generator
  ' Implimented 2011-02-15 by Michael Harris
  
  ' Purpose: To download the contents of a page, and save that page to a static file.
  
  ' Target category: 1 (Contracts)
  ' Target Page:
  ' http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp
  ' Target path: \\servername\sharename\corporate\forms\index.asp
  ' Resulting URL: http://sharename.fpc.wa.gov.au/corporate/forms/index.asp
  
  ' Remove read only
  
  ' Remove read only flag on file if present to allow editing
  ' If file has been set to read only by automated process, turn off read only
  
  
  Const READ_ONLY = 1
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile("\\server\sharename\corporate\forms\index.asp")
  
  If objFile.Attributes AND READ_ONLY Then
      objFile.Attributes = objFile.Attributes XOR READ_ONLY
  End If
  
  Dim webObj, strURL
  Set webObj = CreateObject("Msxml2.ServerXMLHTTP")
  strURL = "http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp"
  
  webObj.Open "GET", strURL
  webObj.send
  
  If webObj.Status=200 Then
  Set objFso = CreateObject("Scripting.FileSystemObject")
  Set txtFile = objFso.OpenTextFile("file:\\servername.fpc.wa.gov.au\sharename\corporate\forms\index.asp", 2, True)
  txtFile.WriteLine webObj.responseText
  txtFile.close
  
  ElseIf webObj.Status &gt;= 400 And webObj.Status &lt;= 599 Then
    MsgBox "Error Occurred : " &amp; webObj.Status &amp; " - " &amp; webObj.statusText
  Else
    MsgBox webObj.ResponseText
  End If
  </code></pre>