简体   繁体   English

无法通过NSIS写入注册表值

[英]Unable to write registry value via NSIS

I want to make my application runs as administrator under Windows 8.1 so I use NSIS to adjust that by adding the following value in Windows registry: 我想让我的应用程序在Windows 8.1下以管理员身份运行,因此我使用NSIS通过在Windows注册表中添加以下值来进行调整:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\MBM\\testo.exe"="~ RUNASADMIN"

The problem is: NSIS doens't write this value into Windows registry although it can write the other ones! 问题是:NSIS不会将此值写入Windows注册表,尽管它可以写入其他值!

NSIS run perfectly as administrator using NSIS作为管理员可以完美运行

RequestExecutionLevel admin

I use the following NSIS snippet for writing in Windows registry (the 1st line and the 2nd work fine while the 3rd doesn't) 我使用以下NSIS代码段在Windows注册表中进行编写(第一行和第二行工作正常,而第三行则行不通)

WriteRegStr HKLM "SOFTWARE\${ORGANIZATION}\${APPNAME}" ClientVersion "${VERSION}"
WriteRegStr HKLM "SOFTWARE\${ORGANIZATION}\${APPNAME}" ClientPath "$INSTDIR"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" $INSTDIR\${APPNAME}.exe "~ RUNASADMIN"

You are not really supposed to write to the AppCompatFlags key. 您实际上不应该写AppCompatFlags键。 Your application should detect that it is not elevated and then notify the user or try to restart itself elevated. 您的应用程序应该检测到它没有提升,然后通知用户或尝试重新启动自己。

If this is a 64 bit system then there will be two AppCompatFlags keys (The other one under Software\\Wow6432Node) and you can use the SetRegView NSIS instruction to choose which key you want to write to. 如果这是64位系统,则将有两个AppCompatFlags密钥(另一个在Software \\ Wow6432Node下),您可以使用SetRegView NSIS指令选择要写入的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM