Set “RUNASADMIN” application compatibility flag in

2019-02-20 05:57发布

问题:

My application was made with Java and it needs Administrator privilege to run on Windows. Using Inno Setup I could change change a registry with the following code and it works just fine for Windows 7, however for Windows 10 and 8, I don't have the same success, since the registry apparently doesn't exist anymore.

[Registry]
Root: HKCR; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"; ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; Flags: uninsdeletekeyifempty uninsdeletevalue;
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"; ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; Flags: uninsdeletekeyifempty uninsdeletevalue;

I read it can be done with the executable manifest, but I suppose it is only for applications made by Visual Studio, which is not my scenario. Is there a way to put it in a Java manifest?

I would like to know if I can do this in some other way, if there is another registry I can modify or if I have to attach and run another kind of script during my instalation.

回答1:

I do not think your problem is related to Windows 7 vs. Windows 8/10. It's rather that your Windows 7 is 32-bit and Windows 8/10 is 64-bit.

The Inno Setup installer is 32-bit application, so SOFTWARE gets redirected to SOFTWARE\Wow6432Node by default.

You have to use an explicit 64-bit registry root like Root: HKLM64 to explicitly avoid the redirection.

You will probably also want to add Check: IsWin64 to make sure the entry is not processed on 32-bit installations, as it would cause an error.

See [Registry] section documentation.

Or use 64-bit install mode.


I also believe that it should not be HKCR, but HKCU.


[Registry]
; keys for 32-bit systems
Root: HKCU32; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; Check: not IsWin64
Root: HKLM32; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; Check: not IsWin64

; keys for 64-bit systems
Root: HKCU64; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; Check: IsWin64
Root: HKLM64; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\AppExecutable.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; Check: IsWin64