首页 > 解决方案 > Inno 更新脚本,访问被拒绝...代码 5

问题描述

这不是我之前问过的同一个问题......我在问为什么在构建到 {commonappdata} 文件夹时出现代码 5 错误。

我有两个 inno 脚本,设置一个为所有用户安装一个应用程序,并将其安装为启动应用程序,因此我们需要管理员权限。我将它设置为安装到 {commonappdata} (ProgramData),以便它成为所有用户的程序。这工作正常。

这是安装脚本:(似乎没有问题)

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

#define MyAppName "xxxx"
#define MyAppVersion "xxxx"
#define MyAppPublisher "xxxxxxx"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "xxxxxx.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={{xxxxxxxxxxxxxxxxxx}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={commonappdata}\{#MyAppName}
DisableDirPage=yes
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.
UsedUserAreasWarning=no
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=admin
OutputBaseFilename=xxxxxx
Compression=lzma
SolidCompression=yes
WizardStyle=modern

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode

[Files]
Source: "C:\xxx\xxxx\Desktop\xxxxxx\xxxxx.exe"; DestDir: "{app}";
Source: "C:\xxx\xxxx\Desktop\xxxxx\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "{#MyAppName}"; ValueData: """{app}\{#MyAppExeName}"""; Flags: uninsdeletevalue

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent




然后更新脚本稍后由 C# 下载(如果有更新的版本),它的整个想法是它更新 {commonappdata} (programdata) 路径,因此它为机器上的每个用户更新,它确实不需要管理员权限即可。同时仍将其作为启动应用程序进行维护。

更新脚本:

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

#define MyAppName "xxxx"
#define MyAppVersion "xxxx"
#define MyAppPublisher "xxxxxxxxxx"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "xxxxxxx.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={{xxxxxxxxxx}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={commonappdata}\{#MyAppName}
DisableDirPage=yes
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.
UsedUserAreasWarning=no
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputBaseFilename=xxxxxx
Compression=lzma
SolidCompression=yes
WizardStyle=modern

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode

[Files]
Source: "C:\xxxx\xxxxx\Desktop\xxxxxxx\xxxxxxxx.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\xxxxx\xxxx\Desktop\xxxxxxxx\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent


我的问题是,当更新脚本运行时,它给了我错误代码:“尝试替换现有文件时发生错误:C:\ProgramData\APP NAME\FILE.EXE: DeleteFile failed; code 5. ACCESS IS拒绝。

请帮忙。我的意思是我知道问题是,我想我什至无法访问或更改 ProgramData 文件夹(不安装时),您需要该文件夹中的管理员权限。但我不知道还有什么地方可以在不需要管理员权限的情况下完成更新(对于每个用户)。

标签: inno-setup

解决方案


您需要管理员权限才能写入commonappdata文件夹。请参阅此处提到的地方:

信息

你让自己很难受。按照设计,您的安装程序要么被提升要么没有。

  • 如果必须使用任何common常量,则需要管理员权限
  • 如果您使用任何auto带有海拔的常量,它只会为用户安装。

推荐阅读