如何使用VbScript检查注册表值

17

我该如何使用VBScript检查注册表值?


你能提供更多的细节吗?例如要检查的注册表键和值的示例,值类型等等。 - Helen
您需要简单地读取该值、检查其是否存在、验证该值本身或其他任何操作吗? - Helen
5个回答

33
Function ReadFromRegistry(strRegistryKey, strDefault)
    Dim WSHShell, value

    On Error Resume Next
    Set WSHShell = CreateObject("WScript.Shell")
    value = WSHShell.RegRead( strRegistryKey )

    If err.number <> 0 Then
        readFromRegistry = strDefault
    Else
        readFromRegistry = value
    End If

    Set WSHShell = Nothing
End Function

使用方法 :

str = ReadfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\ESD\Install_Dir", "ha")
WScript.echo "returned " & str

原始帖子


7

尝试像这样:

Dim windowsShell
Dim regValue
Set windowsShell = CreateObject("WScript.Shell")
regValue = windowsShell.RegRead("someRegKey")

3
这对您应该有效:
Dim oShell
Dim iValue

Set oShell = CreateObject("WScript.Shell")

iValue = oShell.RegRead("HKLM\SOFTWARE\SOMETHINGSOMETHING")

1
Set objShell = WScript.CreateObject("WScript.Shell") 
skey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}\"
with CreateObject("WScript.Shell")
    on error resume next            ' turn off error trapping
    sValue = .regread(sKey)       ' read attempt
    bFound = (err.number = 0)     ' test for success
end with
if bFound then
    msgbox "exists"
else
  msgbox "not exists" 
End If

1

试一下这个。该脚本获取当前已登录用户的用户名和主目录:

On Error Resume Next

Dim objShell, strTemp
Set objShell = WScript.CreateObject("WScript.Shell")

strTemp = "HKEY_CURRENT_USER\Volatile Environment\USERNAME"
WScript.Echo "Logged in User: " & objShell.RegRead(strTemp) 

strTemp = "HKEY_CURRENT_USER\Volatile Environment\USERPROFILE"
WScript.Echo "User Home: " & objShell.RegRead(strTemp) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接