简体   繁体   中英

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:

[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 run perfectly as administrator using

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)

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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