Nsis删除文件夹&子文件夹 - 在安装程序目录中

时间:2015-06-01 07:38:48

标签: windows nsis

如何删除安装程序文件夹中的intel_xdx文件夹。 intel_xdx文件夹中有文件&里面的子目录。此脚本不适合我,我无法删除intel_xdx文件夹。

我甚至在我的脚本中添加了RequestExecutionLevel admin

安装程序适用于Windows 7 PC。

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "uiMagician"
!define PRODUCT_VERSION "1.0.3"
!define PRODUCT_PUBLISHER "Dinesh Guleria"
!define PRODUCT_WEB_SITE "http://www.vscp.org/"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\uiMagician.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "fatbee_v2.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "uiMagicianLicence.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$PROGRAMFILES\uiMagician\uiMagician.exe"
!define MUI_FINISHPAGE_SHOWREADME "$PROGRAMFILES\uiMagician\Readme.txt"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "UiMagician_Setup.exe"
RequestExecutionLevel admin
InstallDir "$PROGRAMFILES\uiMagician"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show


Section "MainSection" SEC01
  SetOutPath "$PROGRAMFILES\uiMagician"
  SetOverwrite ifnewer
  File "uiMagicianLicence.txt"
  File "uiMagician.exe"
  CreateDirectory "$SMPROGRAMS\uiMagician"
  CreateShortCut "$SMPROGRAMS\uiMagician\uiMagician.lnk" "$PROGRAMFILES\uiMagician\uiMagician.exe"
  CreateShortCut "$DESKTOP\uiMagician.lnk" "$PROGRAMFILES\uiMagician\uiMagician.exe"
  File "fatbee_v2.ico"
  File "QtXml4.dll"
  File "QtGui4.dll"
  File "QtCore4.dll"
  File "mingwm10.dll"
  File "libgcc_s_dw2-1.dll"
  File "HelpContent.xml"
  File "Readme.txt"
  File "HISTORY.txt"
  File /a /r "intel_xdx\"
SectionEnd

Section -AdditionalIcons
  SetOutPath $INSTDIR
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\uiMagician\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\uiMagician\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$PROGRAMFILES\uiMagician\uiMagician.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$PROGRAMFILES\uiMagician.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd


Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"
  Delete "$PROGRAMFILES\uiMagician\Readme.txt"
  Delete "$PROGRAMFILES\uiMagician\HelpContent.xml"
  Delete "$PROGRAMFILES\uiMagician\libgcc_s_dw2-1.dll"
  Delete "$PROGRAMFILES\uiMagician\mingwm10.dll"
  Delete "$PROGRAMFILES\uiMagician\QtCore4.dll"
  Delete "$PROGRAMFILES\uiMagician\QtGui4.dll"
  Delete "$PROGRAMFILES\uiMagician\QtXml4.dll"
  Delete "$PROGRAMFILES\uiMagician\sample.ico"
  Delete "$PROGRAMFILES\uiMagician\uiMagician.exe"
  Delete "$PROGRAMFILES\uiMagician\uiMagicianLicence.txt"
  Delete "$PROGRAMFILES\uiMagician\fatbee_v2.ico"
  Delete "$PROGRAMFILES\uiMagician\HISTORY.txt"

  RMDir /r "$PROGRAMFILES\intel_xdx\"

  Delete "$SMPROGRAMS\uiMagician\Uninstall.lnk"
  Delete "$SMPROGRAMS\uiMagician\Website.lnk"
  Delete "$DESKTOP\uiMagician.lnk"
  Delete "$SMPROGRAMS\uiMagician\uiMagician.lnk"

  RMDir "$SMPROGRAMS\uiMagician"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

2 个答案:

答案 0 :(得分:0)

您正在将intel_xdx安装到$PROGRAMFILES\uiMagician\intel_xdx,但您尝试删除$PROGRAMFILES\intel_xdx\

为什么不删除程序的文件夹:

RMDir /r "$SMPROGRAMS\uiMagician"

甚至更好:

  RMDir /r "$INSTDIR"

答案 1 :(得分:0)

Francisco R应该提到使用RMDir /r "$INSTDIR" 不安全。 来自NSIS RMDir documentation

“警告:在卸载程序中使用RMDir / r $ INSTDIR是不安全的。虽然这不太可能,但用户可能选择安装到Program Files文件夹,因此此命令将清除整个Program Files文件夹,包括其他与卸载程序无关的程序。用户还可以放置除该文件的文件以外的其他文件,并希望它们与该程序一起删除。“