Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I asked this question at Stack Overflow but they said I would have better luck here. I am using VBScript to automate a lot of server tasks, I'm simply checking to make sure the server build team did their job before the server actually gets used.

One of my tasks I need to do is Check if there are any Critical Updates. It seems like this would be easy enough but I'm having A LOT of trouble with it. I am not familiar with WSUS, I've never dealt with it but I need to communicate with it.

Here is what I have in my vbscript for this type of logic

'Microsoft Magic
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsAssigned=1 and isHidden=0 and IsInstalled=0 and Type='Software'")
'End Microsoft Magic
If Err.Number <> 0 Then ' If errors
  objResult.Text = "FAIL. Cannot connect to WSUS. Error: " & Err.Number
Else ' No Errors'
    If searchResult.Updates.Count <> 0 Then ' If Updates were found
      For i = 0 to searchResult.Updates.Count - 1 'Just count the number of updates
         count = count + 1
      objResult.Text = "FAIL. There are " & count & " updates that need to be installed"
      objResult.Text = "PASS. All updates are installed"
    End If

  If NOT len(objResult.Text) Then 'Just in case searchResult produces an error
    objResult.Text = "FAIL. Could not query Windows Update Server"
  End If
End If

The output gets sent to an XML file. Anyways, on my test server and on other servers I have tried it on (only two others). It seems to work fine and it passes. In production, I'm getting a lot of errors where I get

FAIL. Could not query Windows Update Server

So, what is happening is it won't connect to Windows Update -- The object "Microsoft.Update.Session" uses the windows update agent to manage whether the updates are being handled by windows update or a WSUS, but sometimes it just doesn't do it and I don't have an explanation or even what I can do.

I've been trying to resolve this a few days but it is hard for me to test it and see it failing, I just get a phonecall stating a server slated for production failed when it isn't suppose to be.

Any suggestions? I can provide more information for clarity if need be.

share|improve this question

Logic looks good; it should have to go through all of the if-else statements to reach the "FAIL. Could not query Windows Update Server" text.

First thought, remove that last if statement and see if you get any print out. It looks like it's overwriting your output.

After that, I'd also try setting isInstalled=1 to make sure it's reading the MS magic properly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.