Check if registry key exists using VBScript

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

    See the Scripting Guy! Blog:

    How Can I Tell Whether a Value Exists in the Registry?

    They discuss doing the check on a remote computer and show that if you read a string value from the key, and if the value is Null (as opposed to Empty), the key does not exist.

    With respect to using the RegRead method, if the term "key" refers to the path (or folder) where registry values are kept, and if the leaf items in that key are called "values", using WshShell.RegRead(strKey) to detect key existence (as opposed to value existance) consider the following (as observed on Windows XP):

    If strKey name is not the name of an existing registry path, Err.Description reads "Invalid root in registry key"... with an Err.Number of 0x80070002.

    If strKey names a registry path that exists but does not include a trailing "\" the RegRead method appears to interpret strKey as a path\value reference rather than as a simple path reference, and returns the same Err.Number but with an Err.Description of "Unable to open registry key". The term "key" in the error message appears to mean "value". This is the same result obtained when strKey references a path\value where the path exists, but the value does not exist.

提交回复
热议问题