通过VBScript获取注册表项的十六进制值

时间:2011-09-19 04:25:31

标签: vbscript registry

认为这是我在注册表中的目标键:

[HKEY_CURRENT_USER\System\Majid\0]
"GUID"=hex:60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00

你可以看到GUID有一个十六进制值,我想告诉一个vb脚本转到这个键并将其十六进制数据存储到一个变量中。

例如,如果目标变量是“目标”,则其值应为“60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00”

任何帮助都得到了真正的赞赏

4 个答案:

答案 0 :(得分:2)

你可能没有答案的原因可能是你的问题的前提是误导,如果没有缺陷的话。这个问题似乎意味着你在问一个十六进制数,但实际上你在询问二进制数据。从注册表导出二进制值时,生成的.reg文件将根据您的示例对十六进制值进行编码。您可能已经或可能没有意识到这一点,但它可能是解决您的问题的绊脚石。

现在回答“如何将二进制值转换为十六进制字符串表示?”

以下代码为我完成了这项工作。我有时只使用vbscript,原谅这种邋。。

Dim objRegistry, target, output
Set objRegistry = CreateObject("Wscript.shell")
target = objRegistry.RegRead("HKCU\System\Majid\0\GUID")
output = ""
for k = LBound(target,1) To UBound(target,1)
    output = output & hex(target(k)) & ","
next
WScript.echo output

这对你有用吗?

答案 1 :(得分:0)

今天写了这些。我仍然需要弄清楚代码中放置了“,”,但是这个将采用REG_MULTI_SZ值并将其转换为正确的十六进制结果,如.reg文件中所示。

'##### READ A REG_MULTI_SZ VALUE CONVERT TO HEX #####

strComputer = "."

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")

Dim oShell
Set oShell = WScript.CreateObject("Wscript.Shell")

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")


regHive = "HKLM"
regKey = "Software\template\templateL2"
regValueName = "SAMPLE-Multi_String"
regPath = regHive & "\" & regKey & "\" & regValueName

regValue = oShell.RegRead(regPath)

res = "" 
prefix = "hex(7):"
For Each item In regValue
data = data & item & vbcrlf
        For i=1 To Len(item)
            r = HexIt(Mid(item,i,1))
            res = res & r
        Next
        res = res & "00,00," 'NEW LINE / ENTRY
    Next
        res = res & "00,00" 'FINAL COMPLETION 



'CONVERT EACH CHARACTER TO ASCII THEN TO HEX, ADD ",00," BETWEEN EACH VALUE
Function HexIt(data)
    a = Asc(data)
    h = Hex(a)
    HexIt = h & ",00,"
End Function


WScript.Echo "ACTUAL DATA IN GUI : " & vbCrLf & data & vbCrLf 
WScript.Echo "HEX REPRESENTATION : " & vbCrLf & res & vbCrLf 

WScript.Echo "REG FILE VALUE     : " & vbCrLf & prefix & res & vbCrLf 

答案 2 :(得分:0)

这是DWORD的一个

'##### READ A DWORD VALUE CONVERT TO HEX #####

strComputer = "."

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")

Dim oShell
Set oShell = WScript.CreateObject("Wscript.Shell")

strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

regHive = "HKLM"
regKey = "Software\template\templateL2"
regValueName = "SAMPLE-Dword"
regPath = regHive & "\" & regKey & "\" & regValueName

regValue = oShell.RegRead(regPath) 'SPECIFY YOUR HIVE\KEY\VALUE HERE
res = "" 
If Len(regvalue) Mod 2 = 0 Then 
    res = "0x"
    leading0 = ""
Else
    res = "0x0"
    leading0 = "0"
End If

WScript.Echo "INPUT DATA IN GUI : " & Hex(regValue)
WScript.Echo "HEX REPRESENTATION: " & res & Hex(regvalue)
WScript.Echo "REG FILE VALUE    : " & "dword:" & leading0 & Hex(regvalue)

答案 3 :(得分:0)

一个用于REG_EXPAND_SZ

'############# READ REG_EXPAND_SZ ##########
strComputer = "."

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")

Dim oShell
Set oShell = WScript.CreateObject("Wscript.Shell")

strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")


regHive = "HKLM"
regKey = "Software\template\templateL2"
regValueName = "Expandable_String"
regPath = regHive & "\" & regKey & "\" & regValueName

regValue = oShell.RegRead(regPath) 
res = "" 
prefix = "hex(2):"

        For i=1 To Len(regValue)
            r = HexIt(Mid(regValue,i,1))
            res = res & r
        Next
        res = res & "00,00" 'NEW LINE / ENTRY



WScript.Echo "INPUT DATA IN GUI : " & regValue
WScript.Echo "HEX REPRESENTATION: " & res 
WScript.Echo "REG FILE VALUE    : " & prefix & res


'CONVERT EACH CHARACTER TO ASCII THEN TO HEX, ADD ",00," BETWEEN EACH VALUE
Function HexIt(data)
    a = Asc(data)
    h = Hex(a)
    HexIt = h & ",00,"
End Function