!define PRODUCT_NAME "softname"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "company"
!define PRODUCT_WEB_SITE "http://www.soft.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\soft.exe" ;Machine
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" ;Machine
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
!include "MUI.nsh"
!define MUI_ABORTWARNING
!define MUI_ICON "softicon.ico"
!define MUI_UNICON "uninstall.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "wellcome.bmp"
!insertmacro MUI_PAGE_WELCOME
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\soft.exe"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\readme.txt"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
Name "${PRODUCT_NAME}"
OutFile "setup.exe"
InstallDir "$PROGRAMFILES\soft"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails hide
ShowUnInstDetails hide
BrandingText "softname"
Section "soft" SEC01
SetOutPath "$INSTDIR"
SetOverwrite on
File /r "D:\soft\*.*"
CreateDirectory "$SMPROGRAMS\soft"
CreateShortCut "$SMPROGRAMS\soft\soft.lnk" "$INSTDIR\soft.exe"
CreateShortCut "$DESKTOP\soft.lnk" "$INSTDIR\soft.exe"
CreateShortCut "$QUICKLAUNCH\soft.lnk" "$INSTDIR\soft.exe"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$SMPROGRAMS\soft\soft website.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\soft\uninstall soft.lnk" "$INSTDIR\uninstall.exe"
WriteRegBin HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\soft" "Order" num(fe:08000000020000007a01000001000000030000007c000000020000006e0000004175674d02000000010000005c003600f3010000c23c1c86200078537d8ff182c496805f8b4e2e006c006e006b002c0003000400efbec23c1c86c23c1c861400000078537d8ff182c496805f8b4e2e006c006e006b00000022000e0000000a00efbe00000000220000000000000000007600000000000000680000004175674d0200000001000000560036009d020000c23c1c862000f182c496805f8b4e2e006c006e006b000000280003000400efbec23c1c86c23c1c8614000000f182c496805f8b4e2e006c006e006b00000020000e0000000a00efbe00000000200000000000000000007c000000010000006e0000004175674d02000000010000005c0036002f000000c23c1c862000f182c496805f8b4e985b517f2e00750072006c002c0003000400efbec23c1c86c23c1c8614000000f182c496805f8b4e985b517f2e00750072006c00000022000e0000000a00efbe0000000022000000000000000000)
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\soft.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\soft.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
Section Uninstall
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\readme.txt"
Delete "$INSTDIR\soft.exe"
Delete "$SMPROGRAMS\soft\uninstall soft.lnk"
Delete "$SMPROGRAMS\soft\soft website.url"
Delete "$QUICKLAUNCH\soft.lnk"
Delete "$DESKTOP\soft.lnk"
Delete "$SMPROGRAMS\soft\soft.lnk"
RMDir "$SMPROGRAMS\soft"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\soft" "Order"
SetAutoClose true
SectionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "are you sure delete $(^Name) ,and all components?" IDYES +2
Abort
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) has delete from your computer"
FunctionEnd
---------------------------------------------------
ps:1、有时候做得很混乱,不如另开一个,重头开始,一点一点整理思绪
2、一定要知道自己做的东西,什么是必须的,可以少走很多弯路,先理清需求
3、做的东西要从玩家的角度出发,傻瓜式虽然看起来很愚蠢,但往往是解决问题的最好办法
4、不必刻意追求技术上的复杂,在技术和时间上做一个有效地平衡