使用 NSIS 卸载 windows 注册表项时,我们是否需要从 windows 注册表中删除每个条目?
When uninstalling the windows registry entry using NSIS, do we need to remove each and every entry from the windows registry?
我的要求是:当我 运行 NSIS 安装程序时,首先它应该检查用户是否有管理用户权限,如果用户有权限然后在安装时,应用程序应该写路径和windows 注册表中的值。
为了检查管理权限,我在
中编写了以下代码片段
.onInit
RequestExecutionLevel admin
Function .onInit
UserInfo::GetAccountType
pop [=12=]
${If} [=12=] != "admin"
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${Else}
MessageBox MB_OK "User is having Administrative Permissions"
${EndIf}
FunctionEnd
如果用户有权限,我写了下面的代码来设置 windows 注册表项。
;--------------------------------
; The stuff to install
Section "RegistryTest (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\RegistryTest
SetOutPath $INSTDIR
; Write the installation path into the registry
;Adding Registry entries under "Dialog"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\Dialog "AppDataDlg" "1"
WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "ReplaceTestWebPage" "http://www.Test.com/tools/upgrade_selector/index.cfm?Localize=true"
WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "UpgradeUpsUrl" "http://www.Test.com/tools/upgrade_selector/Testindex.cfm?Localize=true"
;Adding Registry entries under "EventLogging"
WriteRegStr HKLM SOFTWARE\RegistryTest\EventLogging "ImagePath" "$INSTDIR\eventlog.dat"
;Adding Registry entries under "Notifications"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\Notification "Notification Sounds Enabled" "1"
;Adding Registry entries under "POS"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\POS "Enabled" "0"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpClient" "TestData.exe"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpPacketVer" "1"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpServer" "updates.test.com"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpServerUrl" "/Test/pos/tetstatus.cfm"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ProductCode" "0"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ProductVer" "00"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ZipCode" ""
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "DisplayName" "RegistryTest"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
以下是我的澄清:
我写的管理权限条件是适用于所有操作系统还是有任何特定的操作系统?
我写的代码是先检查权限然后写入注册表。这是正确的方法吗?如果需要修改请提出建议。
在这里我发现了一个观察结果:
我的用户是管理员用户,如果我们使用“HKLM”windows 注册表,那么当 运行“NSIS”安装程序通常或 运行 作为管理员时,它会将其视为管理员用户并转到其他条件并将消息显示为“用户具有管理权限”
如果我使用“HKCU”windows 注册表,那么当 运行“NSIS”安装程序通常会进入“如果”条件并显示“需要管理员权限!”。
如果我 运行 “NSIS” 作为 运行 作为管理员,它会将其视为管理用户并转到其他条件并将消息显示为“用户具有管理权限”。
在这里,为什么“HKLM”和“HKCU”的情况不同?是不是因为“HKLM”会有管理员权限而“HKCU”没有权限。
- 在“卸载”部分,我没有卸载 windows 注册表中的每个部分,而是直接使用 uninstall.exe。但是当卸载它时,它会从 windows 注册表中删除所有条目。那么,这里是不是不需要卸载每个注册表项?
1) 它适用于所有系统。
2) 在 .onInit 中中止是可以的
3) 如果您 运行 是管理员,则不应写信给 HKCU。 UAC 可能导致安装程序 运行 作为 "wrong" 用户,你最终写信给管理员 HKCU 而不是普通用户。
4) DeleteRegKey
将删除键(和子键)中的所有值,您不必手动删除每个项目。
我的要求是:当我 运行 NSIS 安装程序时,首先它应该检查用户是否有管理用户权限,如果用户有权限然后在安装时,应用程序应该写路径和windows 注册表中的值。
为了检查管理权限,我在
中编写了以下代码片段.onInit
RequestExecutionLevel admin
Function .onInit
UserInfo::GetAccountType
pop [=12=]
${If} [=12=] != "admin"
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${Else}
MessageBox MB_OK "User is having Administrative Permissions"
${EndIf}
FunctionEnd
如果用户有权限,我写了下面的代码来设置 windows 注册表项。
;--------------------------------
; The stuff to install
Section "RegistryTest (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\RegistryTest
SetOutPath $INSTDIR
; Write the installation path into the registry
;Adding Registry entries under "Dialog"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\Dialog "AppDataDlg" "1"
WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "ReplaceTestWebPage" "http://www.Test.com/tools/upgrade_selector/index.cfm?Localize=true"
WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "UpgradeUpsUrl" "http://www.Test.com/tools/upgrade_selector/Testindex.cfm?Localize=true"
;Adding Registry entries under "EventLogging"
WriteRegStr HKLM SOFTWARE\RegistryTest\EventLogging "ImagePath" "$INSTDIR\eventlog.dat"
;Adding Registry entries under "Notifications"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\Notification "Notification Sounds Enabled" "1"
;Adding Registry entries under "POS"
WriteRegDWORD HKLM SOFTWARE\RegistryTest\POS "Enabled" "0"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpClient" "TestData.exe"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpPacketVer" "1"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpServer" "updates.test.com"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "HttpServerUrl" "/Test/pos/tetstatus.cfm"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ProductCode" "0"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ProductVer" "00"
WriteRegStr HKLM SOFTWARE\RegistryTest\POS "ZipCode" ""
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "DisplayName" "RegistryTest"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegistryTest" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
以下是我的澄清:
我写的管理权限条件是适用于所有操作系统还是有任何特定的操作系统?
我写的代码是先检查权限然后写入注册表。这是正确的方法吗?如果需要修改请提出建议。
在这里我发现了一个观察结果:
我的用户是管理员用户,如果我们使用“HKLM”windows 注册表,那么当 运行“NSIS”安装程序通常或 运行 作为管理员时,它会将其视为管理员用户并转到其他条件并将消息显示为“用户具有管理权限”
如果我使用“HKCU”windows 注册表,那么当 运行“NSIS”安装程序通常会进入“如果”条件并显示“需要管理员权限!”。 如果我 运行 “NSIS” 作为 运行 作为管理员,它会将其视为管理用户并转到其他条件并将消息显示为“用户具有管理权限”。
在这里,为什么“HKLM”和“HKCU”的情况不同?是不是因为“HKLM”会有管理员权限而“HKCU”没有权限。
- 在“卸载”部分,我没有卸载 windows 注册表中的每个部分,而是直接使用 uninstall.exe。但是当卸载它时,它会从 windows 注册表中删除所有条目。那么,这里是不是不需要卸载每个注册表项?
1) 它适用于所有系统。
2) 在 .onInit 中中止是可以的
3) 如果您 运行 是管理员,则不应写信给 HKCU。 UAC 可能导致安装程序 运行 作为 "wrong" 用户,你最终写信给管理员 HKCU 而不是普通用户。
4) DeleteRegKey
将删除键(和子键)中的所有值,您不必手动删除每个项目。