![]() |
How to detect if registry key is defined
I need to determine if a registry key is defined before I use it. If it's not defined, then I have to define it.
How do I go about detecting if a registry value is defined? Ken |
Use this in a Run Script step (VBScript):
Function RegValueExists(key) Set objSh = CreateObject("WScript.Shell") On Error Resume Next objSh.RegRead(key) RegValueExists = (Err = 0) End Function Builder.LogMessage RegValueExists("HKCU\Control Panel\Opened") or put the function in project/global scripts and reference in a step field like [RegValueExists("HKCU\Control Panel\Opened")] |
When I tried this I get the following error. Any ideas on what I am doing wrong?
-Ken Error expanding macros in property condexpr: The code I am using for the conditional execution is -- [RegValueExists("HKEY_LOCAL_MACHINE\SOFTWARE\Kinook Software\Visual Build Professional\Last Successful Build\%Project% %Unit%")] The code from my global script is ---- Function RegValueExists(key) Set objSh = CreateObject("WScript.Shell") On Error Resume Next objSh.RegRead(key) RegValueExists = (Err = 0) End Function |
Based on the error message, it appears that the RegValueExists function is undefined. Did you add it to project or global scripts (View | Script Editor | Project/Global tab)?
|
OK, I see my mistake. I had placed it in the "Global Subroutines Steps" tabs and not the folder you told me. This fixed it! Thanks.
Ken |
All times are GMT -5. The time now is 07:50 AM. |
Copyright © 1999-2023 Kinook Software, Inc.