Archive: DeleteRegKey problem


DeleteRegKey problem
I'm attempting to clean up previous installations detected in the config section. If detected I attempt to clean up a particular registry entry with:

DeleteRegKey HKCU "Environment\E3ROOT"

This fails and I don't know why. The entry does in fact exist, and I have admin priveleges. Is there a way to get more details on the cause of the error?

Script:

# Auto-generated by EclipseNSIS Script Wizard
# Apr 13, 2007 4:02:47 PM

Name E3

# Defines
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 4.0
!define COMPANY UC
!define URL ""

# MUI defines
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_REGISTRY_KEY ${REGKEY}
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
!define MUI_STARTMENUPAGE_DEFAULTFOLDER E3
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE

# Included files
!include Sections.nsh
!include MUI.nsh

# Variables
Var StartMenuGroup

# Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

# Installer languages
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile setup.exe
InstallDir $PROGRAMFILES\E3
CRCCheck on
XPStyle on
ShowInstDetails show
VIProductVersion 4.0.0.0
VIAddVersionKey ProductName E3
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
VIAddVersionKey FileVersion ""
VIAddVersionKey FileDescription ""
VIAddVersionKey LegalCopyright ""
InstallDirRegKey HKLM "${REGKEY}" Path
ShowUninstDetails show

# Installer sections
Section -Main SEC0000
SetOutPath $INSTDIR\standalone
SetOverwrite on
File /r deploy\standalone\*
WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd

Section -post SEC0001
WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
SetOutPath $INSTDIR
WriteUninstaller $INSTDIR\uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath $SMPROGRAMS\$StartMenuGroup
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_END
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
SectionEnd

Section -config SEC0002
SetOutPath $INSTDIR\standalone
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Case Manager .lnk" $INSTDIR\standalone\E3CaseManager.cmd
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Utility Window .lnk" $INSTDIR\standalone\E3UtilityWindow.cmd
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Admin Tool .lnk" $INSTDIR\standalone\E3AdminTool.cmd
SetOutPath $PROFILE\e3.config
IfFileExists $PROFILE\e3.config\e3commonPrefs.xml 0 +4
MessageBox MB_OK "Detected previous E3 installation... Cleaning up"
Delete $PROFILE\e3.config\e3commonPrefs.xml
DeleteRegKey HKCU "Environment\E3ROOT"
IfErrors 0 +2
MessageBox MB_OK "Error in DeleteRegKey"
ClearErrors
FileOpen $0 $PROFILE\e3.config\e3commonPrefs.xml w
FileWrite $0 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>$\n'
FileWrite $0 '<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">$\n'
FileWrite $0 "<properties>$\n"
FileWrite $0 "<comment>E3 Common Preferences</comment>$\n"
FileWrite $0 '<entry key="E3Home">'
FileWrite $0 $INSTDIR
FileWrite $0 "\standalone"
FileWrite $0 "</entry>$\n"
FileWrite $0 "</properties>$\n"
FileClose $0
SectionEnd

# Macro for selecting uninstaller sections
!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
Push $R0
ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
StrCmp $R0 1 0 next${UNSECTION_ID}
!insertmacro SelectSection "${UNSECTION_ID}"
GoTo done${UNSECTION_ID}
next${UNSECTION_ID}:
!insertmacro UnselectSection "${UNSECTION_ID}"
done${UNSECTION_ID}:
Pop $R0
!macroend

# Uninstaller sections
Section /o un.Main UNSEC0000
RmDir /r /REBOOTOK $INSTDIR\standalone
DeleteRegValue HKLM "${REGKEY}\Components" Main
SectionEnd

Section un.post UNSEC0001
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Case Manager .lnk"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Utility Window .lnk"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Admin Tool .lnk"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
Delete $PROFILE\e3.config\e3commonPrefs.xml
DeleteRegKey /ifempty HKCU "Environment\E3ROOT"
DeleteRegKey HKCU "Environment\MODTRAN_DATA"
DeleteRegKey HKCU "Environment\MODTRAN5_DATA"
DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
DeleteRegValue HKLM "${REGKEY}" Path
DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
DeleteRegKey /IfEmpty HKLM "${REGKEY}"
RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
RmDir /REBOOTOK $INSTDIR
SectionEnd

# Installer functions
Function .onInit
InitPluginsDir
FunctionEnd


# Uninstaller functions
Function un.onInit
ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
!insertmacro SELECT_UNSECTION Main ${UNSEC0000}
FunctionEnd


Seems like E3ROOT is a value and not a key. You should use DeleteRegValue.

DeleteRegValue HKCU Environment E3ROOT

kichik,
Thanks alot, that was it. Pardon my ignorance, it's my first attempt with NSIS, chaulk it up to newbee-ism.