windows - 使用 VBScript 检查注册表项是否存在

标签 windows vbscript registry

我认为这很容易,但显然没有人这样做...... 我正在尝试查看注册表项是否存在。我不在乎它里面是否有任何值,例如(默认)。

这就是我一直在尝试的。

Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
objRegistry.GetStringValue &H80000003,".DEFAULT\Network","",regValue

If IsEmpty(regValue) Then
    Wscript.Echo "The registry key does not exist."
Else
    Wscript.Echo "The registry key exists."
End If

我只想知道 HKEY_USERES\.DEFAULT\.Network 是否存在。我在搜索时发现的大部分内容似乎都在讨论如何操纵它们,并且几乎假设 key 确实存在,因为如果它不存在,它就是神奇地创建的。

最佳答案

我找到了解决方案。

dim bExists
ssig="Unable to open registry key"

set wshShell= Wscript.CreateObject("WScript.Shell")
strKey = "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Digest\"
on error resume next
present = WshShell.RegRead(strKey)
if err.number<>0 then
    if right(strKey,1)="\" then    'strKey is a registry key
        if instr(1,err.description,ssig,1)<>0 then
            bExists=true
        else
            bExists=false
        end if
    else    'strKey is a registry valuename
        bExists=false
    end if
    err.clear
else
    bExists=true
end if
on error goto 0
if bExists=vbFalse then
    wscript.echo strKey & " does not exist."
else
    wscript.echo strKey & " exists."
end if

关于windows - 使用 VBScript 检查注册表项是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9604276/

相关文章:

python - winpexpect 的行为不像 pexpect

windows - 为 Windows 中的目录生成校验和

c - Windows 到 Linux 的 Port C 项目

function - 如何在运行时将函数导入到 QTP 测试中?

windows - 调用 mvn tomcat :run in multiple projects/different directories using a batch file

vbscript - 如何在 VBScript 脚本中断言?

c# - 让 C# 识别 Visual Studio 之外的 dll

windows - 批量语法问题

wix - 使用WiX添加multiString注册表值?

windows - Powershell 设置项属性 : How does one pass a variable to the -value parameter?