Set “RUNASADMIN” application compatibility flag in Inno Setup

痴心易碎 提交于 2019-12-01 09:56:32

问题


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


来源:https://stackoverflow.com/questions/39498971/set-runasadmin-application-compatibility-flag-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!