none
Need help in a VB script for finding the last Microsft patching date RRS feed

  • Question

  • Hi All,

    I have this script for getting the last MS patch date and time from a set of servers. I have pasted just the top few lines because while running the file, I was getting an error. Could somebody help me with this.

    Const OpenAsASCII = 0  
    Const OverwriteIfExist = -1  
    Set oShell = CreateObject("WScript.Shell")  
    Set oFSO = CreateObject("Scripting.FileSystemObject")  
    Set objFSO = CreateObject("Scripting.FileSystemObject")  
    Set outfile = objFSO.CreateTextFile("updates.txt"
     
     
    outfile.WriteLine "Hotfix report date: " & Now & vbCrLf  
     
    Const HKLM = &H80000002 
      
    ' Store the list of server names in a text file named servers.txt 
     
    src = "servers.txt" 
    target = " " 
    Set ts = objFso.OpenTextFile(src,1
     
    On Error resume next 
    Do Until ts.AtEndOfStream 
    target = ts.ReadLine  
    outfile.WriteLine "server name:"&ucase(target)   
     
    ' Query the WMI class to figure out any issues like non windows servers, servers that are down, permission problems etc.        
    Set objWMIService = GetObject("winmgmts:" _  
         & "{impersonationLevel=impersonate}!\\" &target & "\root\cimv2")  
     
    ' If there is an error then it is written to output file, else the subroutine for checking patch deployment status is called. 
     
     
    If Err.Number Then 
    outfile.writeline Err.Description 
    Err.Clear 
    else  
    call testlooping(target) 
    end if 
    outfile.writeline "*********************************************************************" 
    outfile.writeline " " 
    loop 
     
    • Moved by Reed KimbleMVP Friday, February 3, 2012 3:52 PM (From:Visual Basic Language)
    Friday, February 3, 2012 1:40 PM

Answers

  • I would use "On Error Resume Next" only for the one statement you expect to raise an error. Then if there is typo elsewhere you can find it. If you get an error, it might be because the file of server names has a blank line. I would modify the code as follows:

    Const OpenAsASCII = 0
    Const OverwriteIfExist = -1
    Set oShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set outfile = objFSO.CreateTextFile("updates.txt")
    outfile.WriteLine "Hotfix report date: " & Now & vbCrLf
    Const HKLM = &H80000002
    ' Store the list of server names in a text file named servers.txt
    src = "servers.txt"
    Set ts = objFso.OpenTextFile(src,1)
    Do Until ts.AtEndOfStream
        target = Trim(ts.ReadLine)
        If (target <> "") Then
            outfile.WriteLine "server name:"&ucase(target)
            ' Query the WMI class to figure out any issues like non windows servers, servers that are down, permission problems etc.
            On Error Resume Next
            Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" &target & "\root\cimv2")
            ' If there is an error then it is written to output file, else the subroutine for checking patch deployment status is called.
            If Err.Number Then
                outfile.writeline Err.Description
                On Error GoTo 0
            else
                On Error GoTo 0
                call testlooping(target)
            end if
        End If
        outfile.writeline "*********************************************************************"
        outfile.writeline " "
    loop

    ts.Close
    outFile.Close

    -----



    Richard Mueller - MVP Directory Services

    Tuesday, February 7, 2012 2:38 AM
    Moderator

All replies

  • This forum is for the VB.NET language only, not for VBScript questions.
    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by Techie04928 Friday, February 3, 2012 3:48 PM
    • Unmarked as answer by Reed KimbleMVP Friday, February 3, 2012 3:52 PM
    Friday, February 3, 2012 3:08 PM
  • The first thing you should do is comment out the following line so that you can see all errors:

    On Error resume next

    Once that is done, run the script again and let us know what the error is.  Also, if you include a call to a custom function such as testlooping, we would need to know what that function does.


    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP

    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool 2.0
    AD User Creation tool
    Friday, February 3, 2012 6:59 PM
    Moderator
  • I would use "On Error Resume Next" only for the one statement you expect to raise an error. Then if there is typo elsewhere you can find it. If you get an error, it might be because the file of server names has a blank line. I would modify the code as follows:

    Const OpenAsASCII = 0
    Const OverwriteIfExist = -1
    Set oShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set outfile = objFSO.CreateTextFile("updates.txt")
    outfile.WriteLine "Hotfix report date: " & Now & vbCrLf
    Const HKLM = &H80000002
    ' Store the list of server names in a text file named servers.txt
    src = "servers.txt"
    Set ts = objFso.OpenTextFile(src,1)
    Do Until ts.AtEndOfStream
        target = Trim(ts.ReadLine)
        If (target <> "") Then
            outfile.WriteLine "server name:"&ucase(target)
            ' Query the WMI class to figure out any issues like non windows servers, servers that are down, permission problems etc.
            On Error Resume Next
            Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" &target & "\root\cimv2")
            ' If there is an error then it is written to output file, else the subroutine for checking patch deployment status is called.
            If Err.Number Then
                outfile.writeline Err.Description
                On Error GoTo 0
            else
                On Error GoTo 0
                call testlooping(target)
            end if
        End If
        outfile.writeline "*********************************************************************"
        outfile.writeline " "
    loop

    ts.Close
    outFile.Close

    -----



    Richard Mueller - MVP Directory Services

    Tuesday, February 7, 2012 2:38 AM
    Moderator
  • It is impossible to know the "last MS patch Date".

    What is the "last patch date"?

    The last MS patch date, if any, is the last second Tuesday of the month.

    Why do people insist on asking such mindless questions?

    Are you really asking "Whyn was the last time I applied a patch?  Are you asking "when was the last time a Windows Update was run?

    What is the question?

    This is the same queston as when was the last time Venus was visible in the night sky.  Venus is always visible from somewhere.  Why do you think we have GPS?  Why did we invented navigation?

    And what is this line?

    call testlooping(target)

    Why - o - why?

    In our world today every body is a 'tschie' or a 'newbie' .  There are no more stidents and adults. It is all playtime.

    Now that I have vented would you like to ask an intelligent question?

    Don't feel bad about my antagonism. 
    I have suffered much worse at tmercy of this forum. 
    Ha Ha ha ha ah ah ah !!

    Be'la would love you...

    Please comment out every lineof your little complaint.  See how easily it goes away.

    It is true that no one here has even looked at your code?  I bet it is. I bet that even you have not looked closely at it.

    $10 - you are on!


    ¯\_(ツ)_/¯

    Tuesday, February 7, 2012 4:06 AM