Formular una preguntaFormular una pregunta
 

RespondidaCheck OS, Check Hotfix, Install if not present

  • martes, 21 de octubre de 2008 14:31Mark A. Wilson Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi all,
    This may seem like a simple question, but Scripting is not my forte.

    I'm trying to figure out a way to check that the client OS is XPsp3 and then look for the existence of the $NTUninstallKB953760$ folder, and if it is not present, to install \\server\share\WindowsXP-kb953760-x86-ENU.exe.

    Any assistance or advice would be greatly appreciated.

    Thanks, Mark

Respuestas

  • miércoles, 22 de octubre de 2008 6:24Salvador Manaois IIIModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Hi Mark,

    I modified your script a bit to check for whether the patch is installed instead of checking for the uninstall folder.

    1 Set objShell = CreateObject("WScript.Shell")  
    2 Set objFSO = CreateObject("Scripting.FileSystemObject")  
    3  
    4 strComputer = "." 
    5 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
    6 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'")  
    7 For Each objItem In colItems  
    8    If objItem.CSDVersion = "Service Pack 3" Then 
    9       If CheckPatch("KB953760")=True then  
    10          Wscript.Echo "Patch found." 
    11       Else 
    12           Wscript.Echo "Patch not found. Installing patch..." 
    13           objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE  
    14       End if  
    15    End If 
    16 Next 
    17  
    18 Function CheckPatch(patch)  
    19   Set objSession = CreateObject("Microsoft.Update.Session")  
    20   Set objSearcher = objSession.CreateUpdateSearcher  
    21   Set objResults = objSearcher.Search("Type='Software'")  
    22   Set colUpdates = objResults.Updates  
    23   Found = False 
    24   Result = 0  
    25   For i = 0 to colUpdates.Count - 1  
    26       Result = Instr(colUpdates.Item(i).Title, patch)  
    27        If Result > 0 then  
    28          Found = True 
    29          Exit For 
    30        End if  
    31   Next 
    32   CheckPatch = Found  
    33 End Function 

    Regards,

    Salvador Manaois III
    MCSE MCSA CEH MCITP | Enterprise/Server Admin
    Bytes & Badz : http://badzmanaois.blogspot.com
    • Marcado como respuestaMark A. Wilson miércoles, 22 de octubre de 2008 15:54
    •  

Todas las respuestas

  • martes, 21 de octubre de 2008 18:04nckmrtn Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respuesta propuestaTiene código
    Hey Mark,

    Give this a try:

    Set objShell = CreateObject("WScript.Shell"
    Set objFSO = CreateObject("Scripting.FileSystemObject"
     
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'")
    For Each objItem In colItems 
       If objItem.CSDVersion = "Service Pack 3" Then 
          If objFSO.FolderExists("C:\WINDOWS\$NTUninstallKB953760$")=False Then 
             objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE 
          End If 
       End If 
    Next 

    -N
    • Editadonckmrtn martes, 21 de octubre de 2008 18:12
    • Propuesto como respuestaaboren miércoles, 22 de octubre de 2008 5:40
    •  
  • miércoles, 22 de octubre de 2008 5:39aboren Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    nckmrtn said:

    Hey Mark,

    Give this a try:

    Set objShell = CreateObject("WScript.Shell"
    Set objFSO = CreateObject("Scripting.FileSystemObject"
     
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2"
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'")
    For Each objItem In colItems 
       If objItem.CSDVersion = "Service Pack 3" Then' YES XP has SP3, then we check for patch
          If objFSO.FolderExists("C:\WINDOWS\$NTUninstallKB953760$")=False Then'Nope patch is not here, lets install on next line
             objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE'Install patch from share
          End If 
       End If 
    Next 

    -N



    Put some small "helpers" in the script wich by itself is doing the job.
    Checks for SP3 & the actual hotfix.
  • miércoles, 22 de octubre de 2008 6:24Salvador Manaois IIIModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Hi Mark,

    I modified your script a bit to check for whether the patch is installed instead of checking for the uninstall folder.

    1 Set objShell = CreateObject("WScript.Shell")  
    2 Set objFSO = CreateObject("Scripting.FileSystemObject")  
    3  
    4 strComputer = "." 
    5 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
    6 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'")  
    7 For Each objItem In colItems  
    8    If objItem.CSDVersion = "Service Pack 3" Then 
    9       If CheckPatch("KB953760")=True then  
    10          Wscript.Echo "Patch found." 
    11       Else 
    12           Wscript.Echo "Patch not found. Installing patch..." 
    13           objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE  
    14       End if  
    15    End If 
    16 Next 
    17  
    18 Function CheckPatch(patch)  
    19   Set objSession = CreateObject("Microsoft.Update.Session")  
    20   Set objSearcher = objSession.CreateUpdateSearcher  
    21   Set objResults = objSearcher.Search("Type='Software'")  
    22   Set colUpdates = objResults.Updates  
    23   Found = False 
    24   Result = 0  
    25   For i = 0 to colUpdates.Count - 1  
    26       Result = Instr(colUpdates.Item(i).Title, patch)  
    27        If Result > 0 then  
    28          Found = True 
    29          Exit For 
    30        End if  
    31   Next 
    32   CheckPatch = Found  
    33 End Function 

    Regards,

    Salvador Manaois III
    MCSE MCSA CEH MCITP | Enterprise/Server Admin
    Bytes & Badz : http://badzmanaois.blogspot.com
    • Marcado como respuestaMark A. Wilson miércoles, 22 de octubre de 2008 15:54
    •  
  • miércoles, 22 de octubre de 2008 15:55Mark A. Wilson Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks so much for your assistance guys!
  • viernes, 24 de octubre de 2008 14:38Edward Hyde Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Any way to run this against remote computers where the person logged on is only in the users group?
  • viernes, 24 de octubre de 2008 16:17Salvador Manaois IIIModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
     Not possible as the script is installing an OS patch; non-admins will not be able to accomplish this task. Use WSUS if you want to install patches on your clients without explicitly granting users admin rights on their machines.

    http://technet.microsoft.com/en-us/wsus/default.aspx

    Regards,

    Salvador Manaois III
    MCSE MCSA CEH MCITP | Enterprise/Server Admin
    Bytes & Badz : http://badzmanaois.blogspot.com