Check for a Registry Key: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(removed incorrect note) |
No edit summary |
||
Line 1: | Line 1: | ||
{{PageAuthor|Vytautas}} | {{PageAuthor|Vytautas}} | ||
= Method 1 = | |||
The error flag is set if one uses '''EnumRegValue $R0 HKCU My\Reg\Path 0''' and the key does not exist. | |||
= Method 2 = | |||
== Description == | == Description == |
Revision as of 09:51, 3 August 2007
Author: Vytautas (talk, contrib) |
Method 1
The error flag is set if one uses EnumRegValue $R0 HKCU My\Reg\Path 0 and the key does not exist.
Method 2
Description
Include this macro to check to see if a specified registry key exists. After using this macro the stack contains 0 if the key was not present and 1 if it was.
[UPDATE: 2004-04-07]
- Fixed another typo.
[UPDATE: 2003-11-14]
- Fixed a typo in latest version.
[UPDATE: 2003-11-12]
- Added Indexed labels to the macro to enable easier modification if needed.
Usage
!insertmacro IfKeyExists "ROOT" "KeyToCheckIn" "KeyToCheck" Pop $R0 ;$R0 contains 0 (not present) or 1 (present)
The Macro
!macro IfKeyExists ROOT MAIN_KEY KEY push $R0 push $R1 !define Index 'Line${__LINE__}' StrCpy $R1 "0" "${Index}-Loop:" ; Check for Key EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1" StrCmp $R0 "" "${Index}-False" IntOp $R1 $R1 + 1 StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop" "${Index}-True:" ;Return 1 if found push "1" goto "${Index}-End" "${Index}-False:" ;Return 0 if not found push "0" goto "${Index}-End" "${Index}-End:" !undef Index exch 2 pop $R0 pop $R1 !macroend
This page was created due to this thread.
Vytautas