Set WshShell = CreateObject("WScript.Shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set FSO = CreateObject("scripting.filesystemobject")
Set FS = FSO.OpenTextFile(strFileName)
Do While Not(FS.AtEndOfLine)
str = FS.ReadLine
strRegValue = GetRegText(str)
strMyString = Left(strRegValue,(Len(strRegValue) - 1)) '去掉strRegValue中的最后一个"|"符号
s = Split(strMyString, "|")
boolCheckResult1 = CheckType(s(0), s(1))
If boolCheckResult1 Then
boolCheckResult2 = CheckValue(s(0), s(1), s(2))
End If
boolCheckResult = boolCheckResult1 And boolCheckResult2
FormatResult s(0), s(1), s(2), boolCheckResult
Loop
Set FS = Nothing
Set FS2 = Nothing
Set WshShell = Nothing
Set oReg = Nothing
Function GetRegText(str)
strString = ""
Set regEx = New RegExp
ss = "([\S]*)\s([\S]*)\s([\S]*)$"
RegEx.Global = True
RegEx.IgnoreCase = True
RegEx.Pattern = ss
Set objReg = RegEx.Execute(str)
For Each objSubReg In objReg
For Each strValue In objSubReg.Submatches
If strValue = "NULL" Then
strValue = ""
ElseIf strValue = """NULL""" Then
strValue = "NULL"
End If
strString = strString + strValue + "|"
Next
Next
Set RegEx = Nothing
GetRegText = strString
End Function
Function CheckType(strString, strType)
CheckType = False
ss = "([^\\]+)\\(.*)\\(.*)"
Set regEx = New RegExp
regex.Global = True
regEx.IgnoreCase = True
regEx.Pattern = ss
strKeyRoot = regEx.Replace(strString, "$1")
strKeyPath = regEx.Replace(strString, "$2")
arrValueName = regEx.Replace(strString, "$3")
Select Case UCase(strKeyRoot)
Case "HKEY_CLASSES_ROOT"
KeyRoot = HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
KeyRoot = HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
KeyRoot = HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
KeyRoot = HKEY_Users
Case "HKEY_CURRENT_CONFIG"
KeyRoot = HKEY_Current_Config
Case "HKEY_DYN_DATA"
KeyRoot = HKEY_DYN_DATA
End Select
Select Case UCase(strType)
Case "REG_SZ"
arrValueType = REG_SZ
Case "REG_EXPAND_SZ"
arrValueType = REG_EXPAND_SZ
Case "REG_BINARY"
arrValueType = REG_BINARY
Case "REG_DWORD"
arrValueType = REG_DWORD
Case "REG_MULTI_SZ"
arrValueType = REG_MULTI_SZ
End Select
oReg.EnumValues KeyRoot, strKeyPath, arrValueNames, arrValueTypes
If IsNull(arrValueTypes) Then
CheckType = False
Exit Function
End If
For i=0 To UBound(arrValueNames)
If arrValueNames(i) = arrValueName Then
If arrValueTypes(i) = arrValueType Then
CheckType = True
Exit Function
Else
CheckType = False
Exit Function
End If
End If
Next
Set regEx = Nothing
End Function
Function CheckValue(strRegPath, strType, strRegValue)
CheckValue = False
strActualValue = WshShell.RegRead(strRegPath)
If strType <> "REG_BINARY" Then
If CStr(strActualValue) = CStr(strRegValue) Then
CheckValue = True
Exit Function
End If
Else '判断为二进制时是否相等
boolTempResult1 = True
boolTempResult2 = True
For i = 0 To UBound(strActualValue)
strValue = CInt(Right(Left(strRegValue, 2*(i+1)), 2))
If strValue <> strActualValue(i) Then
boolTempResult2 = False
End If
Next
CheckValue = boolTempResult1 And boolTempResult2
Exit Function
End If
End Function
Function FormatResult(strString1, strString2,strString3, boolResult)
If boolResult Then
strHTMLBody = strHTMLBody + "<tr bgcolor=Lime><td>" + strString1 + "</td><td>" + strString2 + "</td><td>" + strString3 + "</td><td>" + "匹配</td></tr>"
Else
strHTMLBody = strHTMLBody + "<tr bgcolor=red><td>" + strString1 + "</td><td>" + strString2 + "</td><td>" + strString3 + "</td><td>" + "不匹配</td></tr>"
End If
End Function
Function GetAllkey(intRoot,strKeyPath)
'函数名称:FileWrite "D:\folder1\file2.txt","写入这些字符"
'函数作用:向指定路径的文件写入数据并保存
'参数:GetAllkey(文件所在路径),words(写入文件的字符)
'示例:GetAllkey HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Internet Explorer"
HKEY_LOCAL_MACHINE=&H80000002
HKEY_CURRENT_USER=&H80000001
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.EnumValues intRoot,strKeyPath,arrValueNames,arrValueTypes
For i=0 To UBound(arrValueNames)
oReg.GetStringValue intRoot, strKeyPath,arrValueNames(i),strvalue
Select Case arrValueTypes(i)
Case 1
typereturn="REG_SZ"
Case 2
typereturn="REG_EXPAND_SZ"
Case 3
typereturn="REG_BINARY"
Case 4
typereturn="REG_DWORD"
Case 7
typereturn="REG_MULTI_SZ"
End Select
GetAllkey=GetAllkey&arrValueNames(i)&", "&typereturn&","&strvalue &vbCrLf
Next
End Function
Public Function FileWrite(pathway,words)
'函数名称:FileWrite "D:\folder1\file2.txt","写入这些字符"
'函数作用:向指定路径的文件写入数据并保存
'参数:pathway(文件所在路径),words(写入文件的字符)
'示例:FileWrite "D:\folder1\file2.txt","写入这些字符"
set fileSystemObj = CreateObject("Scripting.FileSystemObject")
If fileSystemObj.FileExists(pathway) then
Set logFile = fileSystemObj.OpenTextFile(pathway, 2, true)
logFile.WriteLine words
logFile.Close
Else
msgbox "该文件不存在"
End If
Set logFile = Nothing
End Function
[ 本帖最后由 feiyunkai 于 2010-5-7 14:54 编辑 ]作者: ELLKKLLE 时间: 2010-5-7 15:13 标题: 回复 12# 的帖子 Thank you a lot