#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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")] |
#3
|
|||
|
|||
When I tried this I get the following error. Any ideas on what I am doing wrong?
-Ken Error expanding macros in property condexpr: <Error at Line 1, Column 1 (Type mismatch: 'RegValueExists')> 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 |
#4
|
|||
|
|||
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)?
|
#5
|
|||
|
|||
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 |
Thread Tools | |
Display Modes | Rate This Thread |
|
|