NSIS安装程序不写入注册表项

时间:2015-08-18 16:34:13

标签: registry nsis

我正在尝试调试QGIS的NSIS安装程序(卸载时不删除注册表项)。我已经创建了一个简单的测试安装程序来加快这个过程。我的测试安装程序没有编写注册表项。我无法看到我失踪的东西。

运行时,我会看到第一条消息"正在更新注册表"但是我没有看到错误信息。

我在Windows 8.1 Pro上运行。

!include "MUI.nsh"
;NSIS Includes
!include "x64.nsh"
!include "LogicLib.nsh"

;----------------------------------------------------------------------------------------------------------------------------

;Installer Pages

!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_WELCOME

!insertmacro MUI_PAGE_DIRECTORY

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_FINISH

;----------------------------------------------------------------------------------------------------------------------------

; Language files
!insertmacro MUI_LANGUAGE "English"

;----------------------------------------------------------------------------------------------------------------------------

RequestExecutionLevel admin

# define the file name "gupsdata_setup.exe"
Outfile "setup_gupsdata.exe"

# define the installation directory
InstallDir $PROGRAMFILES64\_gups_test

# create read/write test folders
Function .onInit
    CreateDirectory $INSTDIR\read_write\write_me_1
    CreateDirectory $INSTDIR\read_write\write_me_2
    CreateDirectory $INSTDIR\read_only\read_me

    # Make the directory "$INSTDIR\read_write" read write accessible by all users
    AccessControl::GrantOnFile \
        "$INSTDIR\read_write" "(BU)" "GenericRead + GenericWrite"
FunctionEnd

# GUPS Data
Section "GUPS DATA" SecGUPSDATA
    # define the output path for this file
    SetOutPath $PROFILE\GUPSGIS\gupsdata

    # define what to install and place it in the output path
    File .\gupsdata\gupsdata.db
SectionEnd

Section "Registry Update" SecRegUp

    WriteUninstaller "$INSTDIR\Uninstall.exe"

    MessageBox MB_OK "Updating Registry"
    ;Registry Key Entries

    ;HKEY_LOCAL_MACHINE Install entries
    ;Set the Name, Version and Revision of QGIS+ PublisherInfo + InstallPath
    WriteRegStr HKLM "Software\GUPSTEST" "Name" "GUPSTEST"
    WriteRegStr HKLM "Software\GUPSTEST" "VersionNumber" "1"
    WriteRegStr HKLM "Software\GUPSTEST" "VersionName" "TestMe"
    WriteRegStr HKLM "Software\GUPSTEST" "VersionInt" "101011"
    WriteRegStr HKLM "Software\GUPSTEST" "BinaryRevision" "11"
    WriteRegStr HKLM "Software\GUPSTEST" "Publisher" "Me"
    WriteRegStr HKLM "Software\GUPSTEST" "WebSite" "http://web.com"
    WriteRegStr HKLM "Software\GUPSTEST" "InstallPath" "$INSTDIR"

    ;HKEY_LOCAL_MACHINE Uninstall entries
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "DisplayName" "GUPS Test Display name"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "UninstallString" "$INSTDIR\Uninstall.exe"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "DisplayIcon" "$INSTDIR\icons\QGIS.ico"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "EstimatedSize" 1
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "HelpLink" "http://wiki.com"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "URLInfoAbout" "http://wiki.com"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "Publisher" "Me"

    IfErrors 0 +2
        MessageBox MB_OK "Error writing registry entries"

SectionEnd

Section /O "Text File" SecTEXTFILE
    SetOutPath $PROFILE\GUPSGIS\gupsdata
    File .\gupsdata\test.txt

    Var /GLOBAL GUPS_DATA_DIR
    StrCpy $GUPS_DATA_DIR "$PROFILE\GUPSGIS\gupsdata"
SectionEnd

Section "Uninstall"
    DeleteRegKey HKLM "Software\GUPSTEST"
    DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST"
SectionEnd

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${SecGUPSDATA} "Install GUPSDATA"
    !insertmacro MUI_DESCRIPTION_TEXT ${SecRegUp} "Install GUPS Test Registry Entriessu"
    !insertmacro MUI_DESCRIPTION_TEXT ${SecTEXTFILE} "Install Text File"
!insertmacro MUI_FUNCTION_DESCRIPTION_END

更新:我已经尝试了以下代码example,它也无法编写注册表项。

# This installs two files, gupsdata\gupsdata.db and logo.ico, creates a start menu shortcut, builds an uninstaller, and
# adds uninstall information to the registry for Add/Remove Programs

# To get started, put this script into a folder with the two files (gupsdata\gupsdata.db, logo.ico, and license.rtf -
# You'll have to create these yourself) and run makensis on it

# If you change the names "gupsdata\gupsdata.db", "logo.ico", or "license.rtf" you should do a search and replace - they
# show up in a few places.
# All the other settings can be tweaked by editing the !defines at the top of this script
!define APPNAME "App Name"
!define COMPANYNAME "Company Name"
!define DESCRIPTION "A short description goes here"
# These three must be integers
!define VERSIONMAJOR 1
!define VERSIONMINOR 1
!define VERSIONBUILD 1
# These will be displayed by the "Click here for support information" link in "Add/Remove Programs"
# It is possible to use "mailto:" links in here to open the email client
!define HELPURL "http://..." # "Support Information" link
!define UPDATEURL "http://..." # "Product Updates" link
!define ABOUTURL "http://..." # "Publisher" link
# This is the size (in kB) of all the files copied into "Program Files"
!define INSTALLSIZE 12228

RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)

InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}"

# rtf or txt file - remember if it is txt, it must be in the DOS text format (\r\n)
LicenseData "license.rtf"
# This will be in the installer/uninstaller's title bar
Name "${COMPANYNAME} - ${APPNAME}"
Icon "logo.ico"
outFile "sample-installer.exe"

!include LogicLib.nsh

# Just three pages - license agreement, install location, and installation
page license
page directory
Page instfiles

!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
        messageBox mb_iconstop "Administrator rights required!"
        setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
        quit
${EndIf}
!macroend

function .onInit
    setShellVarContext all
    !insertmacro VerifyUserIsAdmin
functionEnd

section "install"
    # Files for the install directory - to build the installer, these should be in the same directory as the install script (this file)
    setOutPath $INSTDIR
    # Files added here should be removed by the uninstaller (see section "uninstall")
    file "gupsdata\gupsdata.db"
    file "logo.ico"
    # Add any other files for the install directory (license files, app data, etc) here

    # Uninstaller - See function un.onInit and section "uninstall" for configuration
    writeUninstaller "$INSTDIR\uninstall.exe"

    # Start Menu
    createDirectory "$SMPROGRAMS\${COMPANYNAME}"
    createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\gupsdata\gupsdata.db" "" "$INSTDIR\logo.ico"

    # Registry information for add/remove programs
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
    # There is no option for modifying or repairing the install
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
    # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
sectionEnd

# Uninstaller

function un.onInit
    SetShellVarContext all

    #Verify the uninstaller - last chance to back out
    MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next
        Abort
    next:
    !insertmacro VerifyUserIsAdmin
functionEnd

section "uninstall"

    # Remove Start Menu launcher
    delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
    # Try to remove the Start Menu folder - this will only happen if it is empty
    rmDir "$SMPROGRAMS\${COMPANYNAME}"

    # Remove files
    delete $INSTDIR\gupsdata\gupsdata.db
    delete $INSTDIR\logo.ico

    # Always delete uninstaller as the last action
    delete $INSTDIR\uninstall.exe

    # Try to remove the install directory - this will only happen if it is empty
    rmDir $INSTDIR

    # Remove uninstaller information from the registry
    DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
sectionEnd

1 个答案:

答案 0 :(得分:4)

操作员错误。在此post中发现的答案。

它是一个32位与64位的东西。我的初始代码将条目写入注册表。我在错误的地方寻找他们。 32位条目写入HKLM \ Software \ Wow6432Node而不是HKLM \ Software。

对于64位应用程序,请在 .onInit和un.onInit函数中使用SetRegView 64。

相关问题