mbnoimi
mbnoimi

Reputation: 440

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"

Upvotes: 0

Views: 410

Answers (1)

Anders
Anders

Reputation: 101569

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.

Upvotes: 1

Related Questions