java 删除注册表_使用NSIS卸载Windows注册表项时,是否需要从Windows注册表中删除每个条目?...

这篇博客讨论了在使用NSIS创建安装程序时如何检查和使用管理员权限来写入Windows注册表。作者提供了检查管理权限的代码片段,并展示了如何在不同操作系统上写入HKLM和HKCU注册表项。在卸载部分,作者询问是否需要在卸载过程中逐个删除注册表项。
摘要由CSDN通过智能技术生成

我的要求是:当我运行NSIS安装程序时,首先它应该检查用户是否具有管理用户权限,如果用户具有权限,那么在安装时,应用程序应该在Windows注册表中写入路径和值 .

要检查管理权限,我在下面写了下面的代码片段

.onInit

RequestExecutionLevel admin

Function .onInit

UserInfo::GetAccountType

pop $0

${If} $0 != "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 "AppDataCollectionDlg" "1"

WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "ReplaceBatteryWebPage" "http://www.APC.com/tools/upgrade_selector/index.cfm?Localize=true"

WriteRegStr HKLM SOFTWARE\RegistryTest\Dialog "UpgradeUpsUrl" "http://www.APC.com/tools/upgrade_selector/index.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 "POT"

WriteRegDWORD HKLM SOFTWARE\RegistryTest\POT "Enabled" "0"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "HttpClient" "PotData.exe"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "HttpPacketVer" "1"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "HttpServer" "updates.apc.com"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "HttpServerUrl" "/pcpe/pot/potstatus.cfm"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "ProductCode" "3"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "ProductVer" "301"

WriteRegStr HKLM SOFTWARE\RegistryTest\POT "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

Below are clarifications I am having:

我写的管理权限条件是否适用于所有操作系统,还是有任何特定的操作系统?

我编写的代码是首先检查权限然后将其写入注册表 . 这是正确的方法吗?如果需要更改,请建议 .

我在这里发现了一个观察结果:

我的用户是Admin用户,如果我们使用“HKLM”Windows注册表,那么当正常运行“NSIS”安装程序或以管理员身份运行时,它会将其视为管理用户并转到其他条件并将消息显示为“用户具有管理权限“

如果我使用“HKCU”Windows注册表,那么当正常运行“NSIS”安装程序时,它将进入“If”状态并显示“需要管理员权限!” . 如果我以管理员身份运行“NSIS”,它将其视为管理用户并转到其他条件并将消息显示为“用户具有管理权限” .

在这里,为什么“HKLM”和“HKCU”的情况会有所不同?是因为“HKLM”将拥有admin privis而“HKCU”将没有权限 .

在卸载部分,我不是直接使用uninstall.exe卸载Windows注册表中的每个部分 . 但卸载它时,将从windows注册中删除所有条目 . 那么,这里是不是需要卸载每个注册表项?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值