Check if registry key exists using VBScript

后端 未结 7 2023
情话喂你
情话喂你 2020-12-29 08:36

I thought this would be easy, but apparently nobody does it... I\'m trying to see if a registry key exists. I don\'t care if there are any values inside of it such as (Defau

7条回答
  •  长情又很酷
    2020-12-29 09:12

    I found the solution.

    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
    

提交回复
热议问题