Noob問題!我需要設置我的安裝目錄
所以到目前爲止,我寫了這個代碼
; NSIS packaging/install script
; Docs: http://nsis.sourceforge.net/Docs/Contents.html
!include LogicLib.nsh
!include nsDialogs.nsh
; --------------------------------
; Variables
; --------------------------------
!define dest "{{dest}}"
!define src "{{src}}"
!define name "{{name}}"
!define productName "{{productName}}"
!define author "{{author}}"
!define version "{{version}}"
!define icon "{{icon}}"
!define setupIcon "{{setupIcon}}"
!define banner "{{banner}}"
!define exec "{{productName}}.exe"
!define regkey "Software\${productName}"
!define uninstkey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productName}"
!define uninstaller "uninstall.exe"
; --------------------------------
; Installation
; --------------------------------
Unicode true
SetCompressor /SOLID lzma
Name "${productName}"
Icon "${setupIcon}"
OutFile "${dest}"
;InstallDir "$PROGRAMFILES\${productName}"
InstallDir $PROGRAMFILES\WhapTk
DirText "This will install WhapTk on your computer. Choose a directory"
InstallDirRegKey HKLM "${regkey}" ""
RequestExecutionLevel admin
CRCCheck on
SilentInstall normal
XPStyle on
ShowInstDetails nevershow
AutoCloseWindow false
WindowIcon off
Caption "${productName} Setup"
; Don't add sub-captions to title bar
SubCaption 3 " "
SubCaption 4 " "
Page custom welcome
Page instfiles
Var Image
Var ImageHandle
Function .onInit
; Extract banner image for welcome page
InitPluginsDir
ReserveFile "${banner}"
File /oname=$PLUGINSDIR\banner.bmp "${banner}"
FunctionEnd
; Custom welcome page
Function welcome
nsDialogs::Create 1018
${NSD_CreateLabel} 185 1u 210 100% "Welcome to ${productName} version ${version} installer.$\r$\n$\r$\nClick install to begin."
;InstallDir $PROGRAMFILES\WhapTk
${NSD_CreateBitmap} 0 0 170 210 ""
Pop $Image
${NSD_SetImage} $Image $PLUGINSDIR\banner.bmp $ImageHandle
SetOutPath $INSTDIR
nsDialogs::Show
${NSD_FreeImage} $ImageHandle
FunctionEnd
; Installation declarations
Section "Install"
WriteRegStr HKLM "${regkey}" "Install_Dir" "$INSTDIR"
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}"
WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"'
WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'
WriteRegStr HKLM "${uninstkey}" "Publisher" "${author}"
WriteRegStr HKLM "${uninstkey}" "DisplayVersion" "${version}"
; Remove all application files copied by previous installation
RMDir /r "$INSTDIR"
; Include all files from /build directory
File /r "${src}\*"
; Create start menu shortcut
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
; Create desktop shortcut
CreateShortCut "$DESKTOP\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
WriteUninstaller "${uninstaller}"
SectionEnd
; --------------------------------
; Uninstaller
; --------------------------------
ShowUninstDetails nevershow
UninstallCaption "Uninstall ${productName}"
UninstallText "Don't like ${productName} anymore? Hit uninstall button."
UninstallIcon "${icon}"
UninstPage custom un.confirm un.confirmOnLeave
UninstPage instfiles
Var RemoveAppDataCheckbox
Var RemoveAppDataCheckbox_State
; Custom uninstall confirm page
Function un.confirm
nsDialogs::Create 1018
${NSD_CreateLabel} 1u 1u 100% 24u "If you really want to remove ${productName} from your computer press uninstall button."
${NSD_CreateCheckbox} 1u 35u 100% 10u "Remove also my ${productName} personal data"
Pop $RemoveAppDataCheckbox
nsDialogs::Show
FunctionEnd
Function un.confirmOnLeave
; Save checkbox state on page leave
${NSD_GetState} $RemoveAppDataCheckbox $RemoveAppDataCheckbox_State
FunctionEnd
; Uninstall declarations
Section "Uninstall"
DeleteRegKey HKLM "${uninstkey}"
DeleteRegKey HKLM "${regkey}"
SetShellVarContext all
Delete "$SMPROGRAMS\${productName}.lnk"
; Remove desktop shortcut
Delete "$DESKTOP\${productName}.lnk"
; Remove whole directory from Program Files
RMDir /r "$INSTDIR"
; Remove also appData directory generated by your app if user checked this option
${If} $RemoveAppDataCheckbox_State == ${BST_CHECKED}
RMDir /r "$APPDATA\${productName}"
${EndIf}
SectionEnd
這些是學校的電腦,所以我希望用戶能夠安裝的exe,他們選擇的文件夾中。 (學校限制了C盤) 我試過
;InstallDir "$PROGRAMFILES\${productName}"
InstallDir $PROGRAMFILES\WhapTk
但是拒絕工作:((安裝程序工作正常,它只是我不能選擇我的目錄) 請告訴我,我做錯了什麼! 在此先感謝
好的,謝謝!我已經得到了「選擇目錄」頁面!但不幸的是,我選擇它安裝的地方沒有得到該文件。無論我做什麼,它都會下載到Program Files文件中! –
在你的'File'指令前加上'SetOutPath $ INSTDIR' – idleberg