0

This isn't the same question I asked before... I'm asking why I am getting code 5 error when building to a {commonappdata} folder.

I have two inno scripts, the setup one installs an application for ALL users, and installs it as a startup application, so we require admin privileges. I set it to install to {commonappdata} (ProgramData) so that it will be the program for all users. This works fine.

Here is the INSTALL script: (Seemingly no issues)

; 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




Then the Update script gets downloaded by C# later (if there is a newer version) and the whole idea of it, is that it updates the {commonappdata} (programdata) path, so it updates for every user on the machine, and it does NOT need admin privileges to do so. While still maintaining it as a startup application.

UPDATE SCRIPT:

; 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


My issue, is that when the update script runs, it gives me the error code: "An error occurred while tryin to replace the existing file: C:\ProgramData\APP NAME\FILE.EXE: DeleteFile failed; code 5. ACCESS IS DENIED.

Please help. I mean I know the problem is, is that I guess I cannot even access or change the ProgramData folder (when not installing) you need admin rights in that folder. But I dont know WHERE else to put it where I can accomplish an update (for every user) without needing admin privileges.

PaffAttack
  • 49
  • 6
  • 1
    Possible duplicate of [Can I create a Inno Updater that wont require admin privileges?](https://stackoverflow.com/questions/57102948/can-i-create-a-inno-updater-that-wont-require-admin-privileges) – Bill_Stewart Jul 19 '19 at 19:07
  • This is my question, I asked that question. But this is a slightly different one, because THAT question was answered, but now I have a access is denied error. So I created a new one. – PaffAttack Jul 19 '19 at 19:10
  • ProgramData folder can not be written to without elevation. – Andrew Truckle Jul 19 '19 at 20:34
  • Will Program File work? I don't want to have to need admin rights when updating. Only Installing.. Maybe appdata? – PaffAttack Jul 19 '19 at 20:55

1 Answers1

0

You need admin rights to write to the commonappdata folder. See here where it mentions:

Info

You are making it hard for yourself. By design your installer is either elevated or not.

  • If you must use any common constant you need admin rights.
  • If you use any auto constant with elevation it is only installed for the user.
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • From my experience, the `commonappdata` is an exception. On the systems I have an access to, I can write to `C:\ProgramData` even without administrator privileges. But maybe it's not true everywhere. – Martin Prikryl Jul 20 '19 at 06:55
  • 1
    But indeed, the OP is going against the architecture of Windows. – Martin Prikryl Jul 20 '19 at 06:57
  • 1
    If `C:\ProgramData` does not work, then `C:\Users\Public` can be an option. See [Is there a shared folder in Windows to which non-elevated users have write access?](https://stackoverflow.com/q/4484305/850848) + Also see https://stackoverflow.com/a/43362205/850848. – Martin Prikryl Jul 20 '19 at 07:00
  • @MartinPrikryl Ok. For me I have to elevation when copying files with File Explorer into this folder. – Andrew Truckle Jul 20 '19 at 07:15