大虾们,给我点思路!
把一些注册表的键值放在一个txt文件里面[ 本帖最后由 ELLKKLLE 于 2010-5-17 10:54 编辑 ] 不用转换类型,读进来就是字符串
读写注册表可以用WScript.Shell对象 给个txt文件的例子啊,一些你可能用到的
读写注册表:
Set WshShell = CreateObject("wscript.shell")
WshShell.RegDelete '删除
WshShell.RegRead '读取
WshShell.RegWrite '写入
读写txt文件
Set FSO = CreateObject("scripting.filesystemobject")
Set FS = FSO.OpenTextFile("C:\test.txt")
Do While(Not(FS.AtEndOfLine))
str1 = FS.ReadLine '按行读取
str2 = FS.Read(1000) '按字节读取
str3 = FS.ReadAll '全部读取
Loop
FS.Close
Set FS = Nothing
Set FSO = Nothing
回复 3# 的帖子
首先谢谢你 呵呵是不是最好保存的不是txt格式而是CSV格式的? 随便啊,txt当然好拉
回复 4# 的帖子
C:\Documents and Settings\Administrator\Application Data\Adersoft\VbsEdit\Temp\MHTREVBC.vbs(6, 9) Microsoft VBScript 运行时错误: 输入超出了文件尾我的意思是:用txt里面的一行去注册表读取相应的值,这个可行吗?
[ 本帖最后由 ELLKKLLE 于 2010-5-6 13:55 编辑 ] 估计是文件太大了?我给的只是一些函数的用法啊,不是程序,不能直接用的,你可以组织一下,自己写来试试嘛
回复 7# 的帖子
就写了不几个字符串。。。。我都没学过,那我试试了。再一次感谢!哎 路漫漫 '需求:
'1.读取.txt文件(里面存放的是一些注册表的键值,包括名称、类型、数据)里面每行,然后去注册表里面的查找,看看是否匹配.
'2.然后输出到一个txt文件或者html文件,分别mathed和notmatched列。
'用法:
'1.将 strFileName 值修改为txt文件的位置, 在txt文件中,每行应该一项相应的注册表信息,依次为 "注册表键值名"<tab>"数据类型"<tab>"键值"如: "HKEY_CURRENT_USER\test\asdf REG_SZ asdf"
'2.如果注册表键值数据类型为二进制,即REG_BINARY型,需要手工进行转换, 如注册表值为 "00 01 02 03 09 0A 0F 11 1F"则应对应为"000102030910151731"
'3.如果注册表的键值为空,则需要用NULL来代替,如果本来值为"NULL", 则需要设置为"NULL", 如 "HKEY_CURRENT_USER\Console\FaceName Reg_sZ "NULL"" 或者 "HKEY_CURRENT_USER\Console\FaceName Reg_sZ NULL"
'4.生成的html文件为当前txt文件的同级目录下,名为 Result.html
On Error Resume Next
Const HKEY_CLASSES_ROOT = 2147483648 '''HKCR
Const HKEY_CURRENT_USER = 2147483649 '''HKCU
Const HKEY_LOCAL_MACHINE = 2147483650 '''HKLM
Const HKEY_Users = 2147483651 '''HKU
Const HKEY_Current_Config = 2147483653 '''HKCC
Const HKEY_DYN_DATA = 2147483654 '''HKDD
Const REG_SZ = 1 '''字符串型
Const REG_EXPAND_SZ = 2 '''扩展字符串型
Const REG_BINARY = 3 '''二进制型
Const REG_DWORD = 4 '''双字节型
Const REG_MULTI_SZ = 7 '''多字符串型
strFileName = "C:\test.txt" '存放注册表信息的地方
'格式化输出
strHTMLHead = "<html><head><title>比较结果</title></head><body><font size=5>文件来源: " + strFileName + ", 比较结果如下:</font><br><br><br><table border=2><tr><td><b>注册表键值名</b></td><td><b>数据类型</b></td><td><b>键值</b></td><td><b>比较结果</b></td></tr>"
strHTMLBody = ""
strHTMLEnd = "</table></body></html>"
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
FS.Close
strFilePath = FSO.GetParentFolderName(strFileName)
strResultFile = strFilePath & Year(Date) & Month(Date) & Day(Date) & "-" & Hour(Time) & Minute(Time)& Second(Time) & "-Result.html"
Set FS2 = FSO.OpenTextFile(strResultFile, 2, True)
FS2.Write(strHTMLHead + strHTMLBody + strHTMLEnd)
FS2.Close
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
如上
[ 本帖最后由 风雪夜归人 于 2010-5-7 11:22 编辑 ] 啥意思?回复需要审核?
回复 9# 的帖子
谢谢获取注册表项下所有键名称、类型、键值(数据),并写入指定TXT文档
'获取注册表项下所有键名称、类型、值,并写入TXT文档'以获取HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer下所有键的名称、类型、数据为例。
FileWrite "D:\folder1\file2.txt",GetAllkey(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Internet Explorer")
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 编辑 ]
回复 12# 的帖子
Thank you a lot
页:
[1]