———————————————————————-
'Checks the registry of each computer listed in INPUT_FILE_NAME
'for a the hotfix listed in HOTFIX
'It uses the WMI registry provider to do this.
'Besides writing to the screen, it writes the output to
'the file in OUTPUT_FILE_NAME in comma delimted format, producing 2 columns:
'the computer name, and the result of the query
'
'21/10/2005 Robert Kloosterhuis: v1.0
'http://www.geekswithblogsnet/jemimus
On Error Resume Next
INPUT_FILE_NAME = "serverlist.txt"
OUTPUT_FILE_NAME = "scan_hotfix_MS05_051.csv"
HOTFIX = "KB902400"
Const FOR_READING = 1
'objFSO.OpenTextFile method uses paramater value 8 to append to file
Const FOR_WRITING = 8
const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Set StdOut = WScript.StdOut
'Set up objFSO variable for file reading and writing operations
Set objFSO = CreateObject("Scripting.FileSystemObject")
'delete OUTPUT_FILE_NAME if it already exists
Set oldfile = objFSO.GetFile(OUTPUT_FILE_NAME)
oldfile.delete
'Set up the output file
Set objOutputFile = objFSO.OpenTextFile(OUTPUT_FILE_NAME, FOR_WRITING, true)
'Read the input file
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
'Make an array out of the list it reads from the input file
arrComputers = Split(strComputers, vbCrLf)
'setting up some initial values
DIM result
DIM noresult
result = 0
noresult = 0
'Our main loop. Everything below this is run for every entry in the imput file
For Each strComputer In arrComputers
'first column in the file we are writing to is the computer name.
'Every bit of info we want to provide is ended with a comma for delimitation
objOutputFile.Write
objOutputFile.Write
objOutputFile.Write strComputer
objOutputFile.Write ","
Err.Clear
'Connect to the WMI registry provider
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _
strComputer & "/root/default:StdRegProv")
'Error Handling If it cant connect to the WMI provider,
'exit with the Error Description
If Err.Number <> 0 Then
Wscript.Echo strComputer & " " & "Error Number " & _
Err.Number & ": " & Err.Description
Err.Clear
Else
'The Registry path we are going to read from
strKeyPath = "SOFTWARE/Microsoft/Windows NT/CurrentVersion/HotFix"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
'Everytime we run though the loop, these values are reset first.
result = 0
noresult = 0
'If it comes across the hotfix we are looking for,
'it changed the value for this loop
For Each Subkey in arrSubKeys
IF Subkey = HOTFIX Then
result = 1
noresult = 0
Else
noresult = 1
End IF
Next
'Now we have a value, lets print some text about it,
'both to the screen, and to our output file
IF result = 1 Then
WScript.Echo strComputer & " " & HOTFIX & " installed!!!"
objOutputFile.Write HOTFIX & " installed!!!"
Else
WScript.Echo strComputer & " " & HOTFIX & " not found!"
objOutputFile.Write HOTFIX & " not found!"
End IF
'End with a comma for this column
objOutputFile.Write ","
end if
'Start a new line
objOutputFile.Writeline
Next
objOutputFile.Close
批量扫描热修复补丁
本文介绍了一种使用VBScript批量检查计算机上特定热修复补丁(如KB902400)安装状态的方法。该脚本通过读取输入文件中列出的计算机名称,并利用WMI查询每台计算机上的注册表,来确定指定热修复补丁是否已安装。查询结果将被写入到输出文件中。
2100

被折叠的 条评论
为什么被折叠?



