Execute postinstall program with administrator privileges in Inno Setup

末鹿安然 提交于 2020-06-13 07:02:46

问题


I'm trying to run another installer at the end of the installation (postinstall). The installer needs administrator provileges. So PrivilegesRequired=admin was added and the error still was there.

Error message below:

Unable to execute file:
C:\Users\User1\AppData\Local\Multi Webcam Video Recorder\webcam.exe

CreateProcess failed; code 740.
The requested operation requires elevation.

#define MyAppName "Multi Webcam Video Recorder"
#define MyAppExeName "webcam.exe"

[Setup]
AppName={#MyAppName}
PrivilegesRequired=admin

[Files]
Source: ..\src\webcam.exe; DestDir: {localappdata}\{#MyAppName}; Flags: ignoreversion

[Run]
Filename: {localappdata}\{#MyAppName}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent

回答1:


With postinstall flag, the program is by default executed with original permissions, even if the installer itself is running with Administrator permissions. To keep the (Administrator) permissions of the installer, add runascurrentuser flag:

[Run]
Filename: {localappdata}\{#MyAppName}\{#MyAppExeName}; \
    Description: {cm:LaunchProgram,{#MyAppName}}; \
    Flags: nowait postinstall skipifsilent runascurrentuser


来源:https://stackoverflow.com/questions/60434553/execute-postinstall-program-with-administrator-privileges-in-inno-setup

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