Old 26th July 2010, 16:19   #1
Squirre1
Member
 
Join Date: Aug 2001
Posts: 55
Send a message via ICQ to Squirre1
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

PHP Code:
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"
        
StrCpy $"Successful"
      
${Else}
        
StrCpy $"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"
        
StrCpy $"Successful"
        
${registry::DeleteKey"HKEY_CLASSES_ROOT\.pdfbkup" $1
        
${If} $== "0"
          
StrCpy $"Successful"
        
${Else}
          
StrCpy $"Failed"
        
${EndIf}
      ${Else}
        
StrCpy $"Failed"
      
${EndIf}
      !
insertmacro logme $INSTLOG "- .pdf association restore result: $0" s
      
!insertmacro logme $INSTLOG "- .pdfbkup cleanup result: $1" s
    
${EndIf}

  
SectionEnd 
Squirre1 is offline   Reply With Quote
Old 26th July 2010, 17:08   #2
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
what about using DeleteRegKey from NSIS, instead of the Registry plug-in ?
Wizou is offline   Reply With Quote
Old 26th July 2010, 17:14   #3
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
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
Wizou is offline   Reply With Quote
Old 26th July 2010, 20:00   #4
Squirre1
Member
 
Join Date: Aug 2001
Posts: 55
Send a message via ICQ to Squirre1
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....
Squirre1 is offline   Reply With Quote
Old 27th July 2010, 08:45   #5
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
Quote:
Originally Posted by Squirre1 View Post
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
Wizou is offline   Reply With Quote
Old 27th July 2010, 14:12   #6
Squirre1
Member
 
Join Date: Aug 2001
Posts: 55
Send a message via ICQ to Squirre1
@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
Squirre1 is offline   Reply With Quote
Old 27th July 2010, 05:46   #7
gringoloco023
Member
 
Join Date: Nov 2009
Posts: 52
Some how ${registry:eleteKey} can not deal with HKCR,
if you use HKLM\SOFTWARE\Classes instead and it works as expected
gringoloco023 is offline   Reply With Quote
Old 27th July 2010, 14:23   #8
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
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.
Wizou is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump