Archive: DeleteKey Not Working


DeleteKey Not Working
  Hey everyone, I just have a real simple bit of code listed below, but for some reason the DeleteKey function that is part of the registry plugin is not workin... I am not sure what is causing it...

I could use the DeleteRegKey, but just getting a handle on the output that is why I am using the deletekey... If someone else can try this and let me know if I am crazy or what...

Thanks,

Squirre1


Name "BackupExt"

>OutFile "BackupExt.exe"
>Caption "$(^Name)"
>XPStyle on
RequestExecutionLevel admin

!include "Registry.nsh"
!include "Sections.nsh"

>var REG_BACKUP

Section "Empty"

ReadRegStr $R9 HKCR ".pdf" ""
${If} $R9 != ""
!insertmacro logme $INSTLOG "Backing up .pdf file association" s
${registry::CopyKey} "HKEY_CLASSES_ROOT\.pdf" "HKEY_CLASSES_ROOT\.pdfbkup" $0
${If} $0 == "0"
StrCpy $0 "Successful"
${Else}
StrCpy $0 "Failed"
${EndIf}
!
insertmacro logme $INSTLOG "- .pdf association backup result: $0" s
StrCpy $REG_BACKUP "1"
${EndIf}

MessageBox MB_OK|MB_ICONINFORMATION "Installation Here" /SD IDOK

${If} $REG_BACKUP == "1"
!insertmacro logme $INSTLOG "Restoring .pdf file association" s
${registry::CopyKey} "HKEY_CLASSES_ROOT\.pdfbkup" "HKEY_CLASSES_ROOT\.pdf" $0
${If} $0 == "0"
StrCpy $0 "Successful"
${registry::DeleteKey} "HKEY_CLASSES_ROOT\.pdfbkup" $1
${If} $1 == "0"
StrCpy $1 "Successful"
${Else}
StrCpy $1 "Failed"
${EndIf}
${Else}
StrCpy $0 "Failed"
${EndIf}
!insertmacro logme $INSTLOG "- .pdf association restore result: $0" s
!insertmacro logme $INSTLOG "- .pdfbkup cleanup result: $1" s
${EndIf}

SectionEnd
>

what about using DeleteRegKey from NSIS, instead of the Registry plug-in ?


additionnally, if you plan to backup .pdf extension association.. instead of creating a .pdfbkup extension entry (WTF?!), it would be better to backup the value in a sub-key of .pdf

like .pdf\MyApp-Backup

or maybe even just save only the (default) value to another name and then change it, instead of replacing the whole .pdf key


I want to make sure the entire contents of the .pdf class are maintained, not just one value, so the easiest thing to do is just copy the key...

Additionally, I can do the DeleteRegKey, BUT my installer is just a wrapper for another msi installation so I am trying to avoid it altering the ErrorLevel which is returned to our management system for successfail validation...

I mean I guess I could do something along the following
GetErrorlevel $2
DeleteRegKey "Path to key"
GetErrorlevel $1
<Handle $1 error result>
SetErrorlevel $2

and go on my marry way... As long as DeleteRegKey will return a valid error result on failure...

But that does not answer why registry::deletekey is not working, even though I can do a DeleteRegKey and it DOES work...

Thanks....


Some how ${registry::DeleteKey} can not deal with HKCR,
if you use HKLM\SOFTWARE\Classes instead and it works as expected


Originally posted by Squirre1
Additionally, I can do the DeleteRegKey, BUT my installer is just a wrapper for another msi installation so I am trying to avoid it altering the ErrorLevel which is returned to our management system for successfail validation...
You're mixing up the ErrorLevel returned by the installer, and the error flag which is a simple internal flag that can be tested by your script after some NSIS instructions.

Unless specified in the documentation, most NSIS instructions don't alter the ErrorLevel, just the error flag.
See also NSIS documentation D.1

@gringoloco023 - Blah, I thought about that, just never tried it. Kept diggin on why it just didnt work in HKCR... HKCR is basically a shortcut to the actual location of HKLM\Software\Classes...

@Wizou - Thanks for that piece... So if an function in NSIS sets the errorflag, it does not actually modify the ErrorLevel, for ex. SetErrorLevel and GetErrorLevel... That was one of my concerns...

I have not had a LOT of time to dig on this because I have been working on other things as well, but you guys helped save me some time..

Thanks,

Squirre1


Only SetErrorLevel, Abort, and a the user clicking Cancel can modify the installer exit code (error level). The errorflag set by NSIS has no effect on the error level.