我可能做得不对,但我正在尝试修改用于查找 Windows 产品密钥的 VBScript,以支持查找 Microsoft Office Pro 的产品密钥。这是代码,但我希望“未知”文件夹名称具有与通配符相同的效果。我知道在 VBScript 中无法使用实际通配符,但我该怎么做才能在不指定“未知”文件夹的情况下在脚本中返回“DigitalProductID”的注册表值?或者我应该在其他地方更改代码?
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Registration\unknown\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
答案1
下一个简单脚本枚举给定注册表项的子项:
Option Explicit
On Error Goto 0
Dim strLog, strComputer, objRegistry, strKeyPath, key, arrsubKeys
strLog = ""
strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Registration\"
strKeyPath = "SOFTWARE\Wow6432Node\Adobe\" '''' key path for demonstration
strLog = strLog & vbNewLine & "subkeys of HKLM\" & strKeyPath
objRegistry.EnumKey HKLM, strKeyPath, arrsubKeys
If VarType( arrsubKeys) = 8204 Then
For Each key In arrsubKeys
strLog = strLog & vbNewLine & key
Next
End If
Wscript.Echo strLog
Wscript.Quit
' useful constants '
' Registry: Braches and Corresponding Hexadecimal Values '
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const HKU = &H80000003 'HKEY_USERS
Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG
Const HKDD = &H80000006 'HKEY_DYN_DATA