Check if registry key exists using VBScript

后端 未结 7 1958
情话喂你
情话喂你 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:20

    In case anyone else runs into this, I took WhoIsRich's example and modified it a bit. When calling ReadReg I needed to do the following: ReadReg("App", "HKEY_CURRENT_USER\App\Version") which would then be able to read the version number from the registry, if it existed. I also am using HKCU since it does not require admin privileges to write to.

    Function ReadReg(RegKey, RegPath)
          Const HKEY_CURRENT_USER = &H80000001
          Dim objRegistry, oReg
          Set objRegistry = CreateObject("Wscript.shell")
          Set oReg = GetObject("winmgmts:!root\default:StdRegProv")
    
          if oReg.EnumKey(HKEY_CURRENT_USER, RegKey) = 0 Then
            ReadReg = objRegistry.RegRead(RegPath)
          else
            ReadReg = ""
          end if
    End Function
    

提交回复
热议问题