IT 专业人士的资源 > 论坛主页 > The Official Scripting Guys Forum! > Check OS, Check Hotfix, Install if not present
提出问题提出问题
 

已答复Check OS, Check Hotfix, Install if not present

  • 2008年10月21日 14:31Mark A. Wilson 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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

答案

  • 2008年10月22日 6:24Salvador Manaois III版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码
    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

全部回复

  • 2008年10月21日 18:04nckmrtn 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     建议的答复包含代码
    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
    • 已编辑nckmrtn 2008年10月21日 18:12
    • 已建议为答案aboren 2008年10月22日 5:40
    •  
  • 2008年10月22日 5:39aboren 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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.
  • 2008年10月22日 6:24Salvador Manaois III版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复包含代码
    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
  • 2008年10月22日 15:55Mark A. Wilson 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Thanks so much for your assistance guys!
  • 2008年10月24日 14:38Edward Hyde 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Any way to run this against remote computers where the person logged on is only in the users group?
  • 2008年10月24日 16:17Salvador Manaois III版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
     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