Skip to content

Commit

Permalink
Merge pull request #178 from OCSInventory-NG/updateversion
Browse files Browse the repository at this point in the history
Fix delete registery key
  • Loading branch information
gillesdubois authored Jul 28, 2020
2 parents 2629a59 + ce3bf40 commit d9824ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
31 changes: 26 additions & 5 deletions NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ setcompressor /SOLID lzma

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "OCS Inventory NG Agent"
!define OLD_PRODUCT_NAME "OCS Inventory Agent"
!define PRODUCT_VERSION "2.7.0.1"
!define PRODUCT_PUBLISHER "OCS Inventory NG Team"
!define PRODUCT_WEB_SITE "http://www.ocsinventory-ng.org"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\OCSInventory.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define OLD_PRODUCT_UNINST_KEY "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\${OLD_PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_SERVICE_NAME "OCS Inventory Service"
!include "FileFunc.nsh"
!include "WordFunc.nsh"
!include "WinVer.nsh"
!include "x64.nsh"
!insertmacro GetTime
!insertmacro WordReplace
;!insertmacro un.GetParent
Expand Down Expand Up @@ -86,11 +89,11 @@ VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Distributed under GNU GP
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${PRODUCT_NAME}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"

BRANDINGTEXT "OCS Inventory"
BRANDINGTEXT "OCS Inventory NG"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "OCS-Windows-Agent-Setup-x64.exe"
InstallDir "$PROGRAMFILES64\OCS Inventory Agent"
#InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowUnInstDetails show

#####################################################################
Expand Down Expand Up @@ -727,7 +730,7 @@ Function FoundOldAgent
sleep 1000

; If old agent detected remove all files
StrCpy $logBuffer "Sarting Old ${PRODUCT_NAME} Version UNISTALL in $R8...$\r$\n"
StrCpy $logBuffer "Sarting Old ${PRODUCT_NAME} Version UNINSTALL in $R8...$\r$\n"
Call Write_Log
; Uninstall NT service
nsExec::ExecToLog "$R8\ocsservice.exe -uninstall"
Expand Down Expand Up @@ -1116,6 +1119,14 @@ FunctionEnd
#####################################################################
Function .onInit
; Init debug log
${IfNot} ${RunningX64}
MessageBox MB_OK|MB_ICONINFORMATION "This program runs on x64 machines only, exiting"
Abort
${EndIf}
${DisableX64FSRedirection}
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${OLD_PRODUCT_UNINST_KEY}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetRegView 64
strcpy $installSatus ";-)"
Delete ${SETUP_LOG_FILE}
StrCpy $logBuffer "********************************************************$\r$\n"
Expand Down Expand Up @@ -1557,6 +1568,14 @@ UpgradeSkipUnregister:
Call Write_Log
ClearErrors
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent"
IfErrors 0 +3
StrCpy $logBuffer "Failed to remove key, but non blocking !"
Call Write_Log
; Remove old uninstall registry key
StrCpy $logBuffer "$\r$\n$\tRemoving old uninstall key <HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent>..."
Call Write_Log
ClearErrors
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent"
IfErrors 0 +3
StrCpy $logBuffer "Failed to remove key, but non blocking !"
Call Write_Log
Expand Down Expand Up @@ -1935,7 +1954,7 @@ Function un.onInit
Pop $R9
StrLen $0 $R9
IntCmp $0 2 unOnInit_silent 0 unOnInit_silent
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure to unistall $(^Name)?" IDYES +2
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure to uninstall $(^Name)?" IDYES +2
Abort
unOnInit_silent:
FunctionEnd
Expand All @@ -1946,7 +1965,8 @@ FunctionEnd
#####################################################################
Section Uninstall
SetShellVarContext all
StrCpy $logBuffer "Sarting ${PRODUCT_NAME} ${PRODUCT_VERSION} UNISTALL...$\r$\n"
SetRegView 64
StrCpy $logBuffer "Sarting ${PRODUCT_NAME} ${PRODUCT_VERSION} UNINSTALL...$\r$\n"
Call un.Write_Log
Call un.StopService
; Uninstall NT service
Expand All @@ -1971,6 +1991,7 @@ Section Uninstall
RMDir /r /REBOOTOK "$INSTDIR"
; Remove registry key
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${OLD_PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
Expand Down
4 changes: 4 additions & 0 deletions NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ setcompressor /SOLID lzma

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "OCS Inventory NG Agent"
!define OLD_PRODUCT_NAME "OCS Inventory Agent"
!define PRODUCT_VERSION "2.7.0.1"
!define PRODUCT_PUBLISHER "OCS Inventory NG Team"
!define PRODUCT_WEB_SITE "http://www.ocsinventory-ng.org"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\OCSInventory.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define OLD_PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${OLD_PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_SERVICE_NAME "OCS Inventory Service"
!include "FileFunc.nsh"
Expand Down Expand Up @@ -1073,6 +1075,7 @@ FunctionEnd
#####################################################################
Function .onInit
; Init debug log
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${OLD_PRODUCT_UNINST_KEY}"
strcpy $installSatus ";-)"
Delete ${SETUP_LOG_FILE}
StrCpy $logBuffer "********************************************************$\r$\n"
Expand Down Expand Up @@ -1928,6 +1931,7 @@ Section Uninstall
RMDir /r /REBOOTOK "$INSTDIR"
; Remove registry key
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${OLD_PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
Expand Down

0 comments on commit d9824ae

Please sign in to comment.