我的安装程序将Uninstall.exe和/ temp /目录复制到安装文件夹(对我来说是C:\ MyExample),但MyExample.dll / ico / exe和success / error.wav直接复制到C: \而我无法正常工作。
!include "MUI2.nsh"
;General
Function .onInit
ReadEnvStr $R0 SYSTEMDRIVE
StrCpy $INSTDIR `$R0\MyExample\`
FunctionEnd
Name "MyExample"
OutFile "Setup.exe"
RequestExecutionLevel admin
;--------------------------------
!define MUI_ABORTWARNING
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define MUI_FINISHPAGE_SHOWREADME ""
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION finishpageaction
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
File "MyExample.exe"
File "MyExample.ico"
File "error.wav"
File "success.wav"
File "MyExample.dll"
CreateDirectory $INSTDIR\temp
SetOutPath "$INSTDIR"
WriteRegStr HKCU "Software\MyExample" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Product\MyExample" \
"MyExample" "$\"$INSTDIR\uninstall.exe$\""
SectionEnd
Section "Uninstall"
# Always delete uninstaller first
delete $INSTDIR\uninstall.exe
delete $INSTDIR\MyExample.exe
delete $INSTDIR\MyExample.ico
delete $INSTDIR\error.wav
delete $INSTDIR\success.wav
delete $INSTDIR\MyExample.dll
SectionEnd
;--------------------------------
;Descriptions
LangString DESC_SecDummy ${LANG_ENGLISH} "Setup"
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\MyExample"
SectionEnd
Function LaunchLink
ExecShell "" "$INSTDIR\MyExample.exe"
FunctionEnd
Function finishpageaction
CreateShortcut "$desktop\MyExample.lnk" "$instdir\MyExample.exe"
WriteRegStr HKEY_CURRENT_USER "Software\Microsoft\Windows\CurrentVersion\Run" \
"MyExample.exe" "$INSTDIR\MyExample.exe"
FunctionEnd
答案 0 :(得分:4)
在Dummy Section
部分中,您正在安装某些文件而不告知目标目录。我想这隐含地意味着$INSTDIR
,但你需要明确,因为可能会或可能不会选择一个部分(当你有多个部分时),并且它们不能依赖先前执行的部分的副作用(如果有的话)
在File
语句之前的部分开头添加目标文件夹:
SetOutPath $INSTDIR