'Access denied' 当 运行 安装程序使用 CreateAppDir=no 和 PrivilegesRequired=lowest

'Access denied' when running installer with CreateAppDir=no and PrivilegesRequired=lowest

我立即收到 “访问被拒绝” 错误。

这是我的 .iss 文件:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "MyApp"
#define MyAppVersion "1.5"
#define MyAppPublisher "InteXX"
#define MyAppURL "https://www.intexx.com/"
#define MyAppExeName "MyApp.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{2F651F6A-6F25-4B73-BC69-C2DC1E04420F}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputBaseFilename=MyApp
SetupIconFile=D:\Dev\Projects\Testing\MyApp\MyApp\Icon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\Dev\Projects\Testing\MyApp\Config\bin\Debug\Config.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Work\AppData\Local\InteXX\MyApp\Releases\Setup.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: "{tmp}\MyApp\Config.exe"; Flags: waituntilterminated skipifdoesntexist
Filename: "{tmp}\MyApp\Setup.exe"; Flags: waituntilterminated skipifdoesntexist

...这是错误消息:

里面有this Q&A,里面讨论的也是同样的错误,但是里面的场景和我的有点不一样。 OP 正试图在 安装成功后 打开一个文件。我试图让我的安装程序首先进入 运行。

我尝试稍微修改 DestDir 值:

DestDir: "{app}\MyApp";

...和:

DestDir: "{app}\MyApp\";

然而,这些也失败了。

一些注意事项:

  • Setup.exe 是一个 Squirrel-generated 安装文件
  • Config.exe 是一个小型存根可执行文件,除了设置 SQUIRREL_TEMP 环境变量以为 MyApp
  • 指定自定义安装文件夹外,它什么都不做
  • 我使用 Inno 的唯一原因是我可以在 Squirrel 之前设置变量的值 运行s
  • 我有意省略了 .iss 文件中的任何目标目录,因为 Squirrel 将使用变量
  • 中包含的值

鉴于以上情况,我应该如何修改我的 .iss 文件才能成功安装?


编辑 1:根据 Lex 在评论中的建议,我对我的 .iss 文件做了一些更改:

[Files]
Source: "D:\Dev\Projects\Testing\MyApp\Config\bin\Debug\Config.exe"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "D:\Dev\Projects\Testing\MyApp\MyApp\bin\Debug\Setup.exe"; DestDir: "{tmp}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: "{tmp}\Config.exe"; Flags: waituntilterminated skipifdoesntexist; WorkingDir: {tmp}
Filename: "{tmp}\Setup.exe"; Flags: waituntilterminated skipifdoesntexist; WorkingDir: {tmp}

但是,问题依然存在。


编辑 2:根据 Martin 在评论中的要求,这是一个日志文件:

2020-07-11 11:36:03.621   Log opened. (Time zone: UTC-08:00)
2020-07-11 11:36:03.621   Setup version: Inno Setup version 6.0.5 (u)
2020-07-11 11:36:03.621   Original Setup EXE: D:\Dev\Projects\Testing\MyApp\MyApp\Output\MyApp.exe
2020-07-11 11:36:03.621   Setup command line: /SL5="E1D68,3097553,911872,D:\Dev\Projects\Testing\MyApp\MyApp\Output\MyApp.exe" 
2020-07-11 11:36:03.622   Windows version: 10.0.18363  (NT platform: Yes)
2020-07-11 11:36:03.622   64-bit Windows: Yes
2020-07-11 11:36:03.622   Processor architecture: x64
2020-07-11 11:36:03.622   User privileges: None
2020-07-11 11:36:03.625   Administrative install mode: No
2020-07-11 11:36:03.625   Install mode root key: HKEY_CURRENT_USER
2020-07-11 11:36:03.713   64-bit install mode: No
2020-07-11 11:36:03.719   Created temporary directory: C:\Users\Work\AppData\Local\Temp\is-1AIP0.tmp
2020-07-11 11:36:07.329   Found 2 files to register with RestartManager.
2020-07-11 11:36:07.329   Calling RestartManager's RmGetList.
2020-07-11 11:36:07.347   RmGetList finished successfully.
2020-07-11 11:36:07.348   RestartManager found no applications using one of our files.
2020-07-11 11:36:07.431   Starting the installation process.
2020-07-11 11:36:07.448   Directory for uninstall files: C:\WINDOWS
2020-07-11 11:36:07.448   Creating new uninstall log: C:\WINDOWS\unins000.dat
2020-07-11 11:36:07.448   Fatal exception during installation process (Exception):
                          CreateFile failed; code 5.
                          Access is denied.
2020-07-11 11:36:07.448   Exception message:
2020-07-11 11:36:07.448   Message box (OK):
                          CreateFile failed; code 5.
                          Access is denied.
2020-07-11 11:36:11.110   User chose OK.
2020-07-11 11:36:11.110   Message box (OK):
                          Setup was not completed.
                          
                          Please correct the problem and run Setup again.
2020-07-11 11:36:12.193   User chose OK.
2020-07-11 11:36:12.193   Rolling back changes.
2020-07-11 11:36:12.211   Starting the uninstallation process.
2020-07-11 11:36:12.211   Uninstallation process succeeded.
2020-07-11 11:36:13.712   Deinitializing Setup.
2020-07-11 11:36:13.783   Log closed.

我现在知道问题出在哪里了,但我仍然不知道如何解决它。显然,我需要将卸载文件放在 C:\WINDOWS 以外的地方,但我还不确定该怎么做。

您的安装程序已将 CreateAppDir 设置为 no。对于这种情况,文档天数:

If the uninstall feature is enabled when CreateAppDir is no, the uninstall data files are created in the system's Windows directory.


解决问题:

  • 如果您需要卸载程序,则必须将其存储在某个地方。如果您的安装程序不需要任何管理员权限(因此您不能写入系统目录),您将必须为卸载程序文件创建文件夹。所以不要将 CreateAppDir 设置为 no。您可以使用 DefaultDirName 自定义安装文件夹以使用不需要管理员权限的文件夹。最佳做法是使用 {autopf} constant.

    [Setup] 
    CreateAppDir=yes
    DefaultDirName={autopf}\My Program
    
  • 或者您实际上不需要卸载程序。然后将 Uninstallable 设置为 no.

    [Setup] 
    Uninstallable=no
    

    另见