0

我的安装程序将 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
4

1 回答 1

4

在您的Dummy Section部分中,您正在安装一些文件而不告诉目标目录。我想这是隐含的意思$INSTDIR,但是您需要明确说明可能会或可能不会选择一个部分(当您有多个部分时),并且它们不能依赖于先前执行的部分的副作用(如果有的话)。

在该部分的开头,在File语句之前添加目标文件夹:

SetOutPath $INSTDIR
于 2013-06-21T11:44:58.483 回答