0

First inno installer, installs the app as a startup application, which obviously requires admin privileges. But when we update our already existing program, I don't want to have to require admin rights (this allows us to auto update)

Here is the first installer script that requires admin privileges.

; 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




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=none
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


Now I want to write a update installer that wont require admin rights and just update the files.. This is a startup application, that is the only reason it requires admin rights. And it has to be a startup application.

PaffAttack
  • 49
  • 6

1 Answers1

0

You install the software for one user only (C:\Users\...):

[Files]
Source: "C:\Users\*****\Desktop\****\******.exe"; DestDir: "{app}"; Flags: ignoreversion

Yet you set it up to be started for all users (HKLM):

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

That's wrong. Windows will try to run the software for each user that logs in to the machine. Yet only that one user, will have access to the software. So the startup will fail for the others.

If you want to install the software for one users only, add the startup entry to the Run key to HKCU (current user) hive only, not HKLM (local machine).


Btw, for an answer to your literal question, see
Choose right Windows directory to install software and allow auto-updates
But your question is XY problem, so I believe that you actually do not want, what you ask for.


If you actually do not mind that any user can modify/hack/infect the application, you can create two installers.

One, that will do the initial installation:

  • Writes the files to a folder, where all users have a write access, like {commonappdata}.
  • Creates the [Run] entry in the HKLM – For what it needs PrivilegesRequired=admin.

Other, that will update the program only:

  • Updates the files in {commonappdata}
  • Does not modify the registry – So it can do with PrivilegesRequired=lowest.

Both installers should have the same AppId, so that they can share installation data. Though, I'm not sure, if it that will work nicely in Inno Setup 6, with its Side-by-side installation feature.

Well, in general you doing something that's not really correct.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • If I wanted to install it for all users... Would I make the directory something other than users? Thanks! – PaffAttack Jul 19 '19 at 13:35
  • Of course, then you should install the application to `C:\Program Files` – `{pf}`. – Martin Prikryl Jul 19 '19 at 14:19
  • I can't test it now since the admin is gone today. But if I change the program files to something for all users... Then take out the HKLM and replace it with HKCU.. I should be able to update the files without writing to anything that has privilege and it will still be a startup program? The only thing I did with regards to HKLM and HKCU is I just switched HKLM with HKCU... I think that was enough based on what you were telling me. – PaffAttack Jul 19 '19 at 14:29
  • I'm not sure I understand what you want. If you want the application to be updated without administrator privileges, then either 1) You need a service as shown in the linked question. 2) or the application needs to be installed into a folder, where all users (or at at last those that should be able to update the application) have a write access to. What also means all those users can modify/hack/infect the application any way they like. – Martin Prikryl Jul 19 '19 at 14:33
  • Well I have a C# Script that downloads the newest version (if there is one) and then automatically runs an inno setup .exe that has been compiled.. I don't really care THAT much if they hack the program since we secure it as well on the server side. Basically the program needs to install as a startup application by default (requires admin) if it could install for all users OR just one user, that would be great. But then I need the program to be able to automatically download the newest installer.exe and then update the files, while still maintaining itself as a startup program,with no admin – PaffAttack Jul 19 '19 at 14:37
  • If you are ok with installing it for *one user*, then you do not need administrator privileges even for the initial installation - As my answer already says. – Martin Prikryl Jul 19 '19 at 14:39
  • Even to make it be a default startup program? I thought you needed admin rights in order to modify startups. I will try your suggestion. – PaffAttack Jul 19 '19 at 15:31
  • Okay I got it to work as startup program for ONE user without admin rights... Can you explain again what I need to change in order for it to be for ALL users on the machine as a startup? Its just the install path location , right? – PaffAttack Jul 19 '19 at 15:57
  • I am okay with needing admin for first time mass install all users. The other install I would like to have no admin required and it updates the files. Will admin be needed for that? If yes, but it updates it for EVERY user on the PC when they do it once, then that isn't so bad I guess. – PaffAttack Jul 19 '19 at 16:07
  • One of locations, where all users can write to is `C:\ProgramData` = `{commonappdata}`. + It would be way easier to make separate installers for the initial install and for the update (with the same `AppId`). Otherwise you would have to [elevate the installer for the first install programmaticaly](https://stackoverflow.com/q/21556853/850848). – Martin Prikryl Jul 19 '19 at 16:21
  • Oh yeah I am going to have two installers. Okay you are being helpful, thank you... I am confused about the {commonappdata} part. Currently what I have is: ```DefaultDirName=C:\ProgramData\{#MyAppName}``` This is what you meant, right? – PaffAttack Jul 19 '19 at 16:29
  • It should be `DefaultDirName={commonappdata}\{#MyAppName}` – See [Inno Setup - Constant for 'ProgramData' directory?](https://stackoverflow.com/q/39655574/850848) – Martin Prikryl Jul 19 '19 at 16:32
  • So then to mass install for users I changed it back to HKLM and then on my update installer script I don't mess with the HKLM at all? – PaffAttack Jul 19 '19 at 16:34
  • Yes, your update script won't have any `[Registry]` entry. – Martin Prikryl Jul 19 '19 at 16:36
  • I have updated my original post with my new InstallScript and then I included my UpdateScript. Can you look them both over and tell me if the requirements of: Install for all users as a startup program (admin is okay to require) and then the update script will Update all users application (with no admin required) and maintaining as a startup. THANK YOU – PaffAttack Jul 19 '19 at 16:41
  • Your last update is "Well, in general you doing something that's not really correct." ? Dang. Well is it going to work? I seem to have conformed the scripts to the specifications (I believe) you talked about. You are being so helpful, thank you its almost over. – PaffAttack Jul 19 '19 at 16:45
  • When I run my update script and then install the EXE , it says that an error occured while trying to replace the existing file: DeleteFile failed; code 5. Access is denied. ``` The location is C:\ProgramData\*my program name*\files\files ``` – PaffAttack Jul 19 '19 at 17:52
  • Can the user that runs the update installer write to the folder? Did you try to modify/delete the files in Windows File Explorer? – Martin Prikryl Jul 20 '19 at 06:54