Inno Setup is unable to install to LocalSystem's %LOCALAPPDATA% - inno-setup

I have a Windows service that runs as the local system account. It stores some data in its %LOCALAPPDATA% folder. For LocalSystem, this is the following location:
C:\Windows\system32\config\systemprofile\AppData\Local
This works without a hitch; the service creates its own subfolder and writes files to it.
Now, using Inno Setup, I'm trying to install an initial file to that folder:
[Files]
Source: "LICENSE"; DestDir: "{sys}\config\systemprofile\AppData\Local\InnoTest"; Flags: ignoreversion
The log suggests that this works fine:
[14:20:10,722] -- File entry --
[14:20:10,725] Dest filename: C:\Windows\system32\config\systemprofile\AppData\Local\InnoTest\LICENSE
[14:20:10,729] Time stamp of our file: 2022-10-24 13:56:42.000
[14:20:10,731] Installing the file.
[14:20:10,734] Creating directory: C:\Windows\system32\config\systemprofile\AppData\Local\InnoTest
[14:20:10,738] Successfully installed the file.
It says "successfully installed the file", but neither the file nor the directory is anywhere to be seen.
Run the installer again, however, and you will be told that the destination file exists:
[14:24:47,381] -- File entry --
[14:24:47,395] Dest filename: C:\Windows\system32\config\systemprofile\AppData\Local\InnoTest\LICENSE
[14:24:47,398] Time stamp of our file: 2022-10-24 13:56:42.000
[14:24:47,400] Dest file exists.
[14:24:47,403] Time stamp of existing file: 2022-10-24 13:56:42.000
[14:24:47,405] Installing the file.
[14:24:47,410] Successfully installed the file.
So: The installer thinks the file exists, but I can't see it.
This is specifically an issue with the System account; if I switch to, say, the %LOCALAPPDATA% of the LocalService account, things work as expected:
[Files]
Source: "LICENSE"; DestDir: "{win}\ServiceProfiles\LocalService\AppData\Local\InnoTest"; Flags: ignoreversion
If anyone could shed some light on what is (or isn't) going on here, it would be much appreciated.
Minimal, reproducible and complete example here.

This is almost a duplicate of:
File/DLL installed to {sys} does not appear in C:\Windows\system32
Though your question probably deserves specific answer.
If I understand correctly, you want to install to System32 on both 32-bit and 64-bit systems. So there are two options:
Use the 64-bit mode;
If you do not want (or not dare) to switch whole installer to 64-bit mode, you will need two entries in the [Files] section. One for 64-bit systems with 64bit flag and one for 32-bit systems without the flag:
[Files]
Source: "LICENSE"; \
DestDir: "{sys}\config\systemprofile\AppData\Local\InnoTest"; \
Flags: ignoreversion; Flags: 64bit; Check: IsWin64
Source: "LICENSE"; \
DestDir: "{sys}\config\systemprofile\AppData\Local\InnoTest"; \
Flags: ignoreversion; Check: not IsWin64

Related

Conditionally include folders in Inno Setup

I'm trying to create an installer with Inno Setup that will statically include a folder if it exists. This folder will be installed on the user system if a specific directory already exists on the user's system.
For example, there are configurations specific to 2017, 2018, 2019. If I have a CC2017 folder, then include it in the installer. The installer will put the folder on the user's system in their 2017 folder if it exists.
I use variables to define some of the path and have formatted them without brackets based on the answer here.
#ifexist projpath + "\" + reponame + "\Plug-Ins\Windows\CC2017\"
Source: "{#projpath}\{#reponame}\Plug-Ins\Windows\CC2017\{#pluginname}\*"; \
DestDir: "{sd}\Program Files\Adobe\Adobe InDesign CC 2017\Plug-Ins\{#pluginname}"; \
Flags: ignoreversion recursesubdirs createallsubdirs replacesameversion; \
Check: MyDirCheck(ExpandConstant('{sd}\Program Files\Adobe\Adobe InDesign CC 2017'))
#endif
I know it isn't checking correctly because the file size is much smaller when I add the ifexist directives. The Inno Setup docs mention "files" but not folders so I'm suspicious that it might not support checking folders.
What is wrong with the syntax?
I'm using Inno Setup 6.0.2 on Mac 10.13.6
There are two options:
Use skipifsourcedoesntexist flag:
[Files]
Source: "folder\*"; DestDir: "{app}"; Flags: skipifsourcedoesntexist
Use #if preprocessor directive along with DirExists preprocessor function:
[Files]
#if DirExists("folder")
Source: "folder\*"; DestDir: "{app}"
#endif

Install only if external file exists

I would like to instruct Inno Setup to install a certain external file only if does exist.
Like so:
Source: "d:\sources\SomeDLL.dll"; DestDir: {app}; \
Flags: external regserver uninsneveruninstall ignoreversion
However, I did not find a flag that would instruct Inno Setup to skip this line / file if d:\sources\SomeDLL.dll does not exist.
Is this possible?
Thank you!
Use the skipifsourcedoesntexist flag:
This flag instructs the compiler -- or Setup, if the external flag is also used -- to silently skip over the entry if the source file does not exist, instead of displaying an error message.
Try this flag:
onlyifdestfileexists
Only install the file if a file of the same name already exists on the user's system. This flag may be useful if your installation is a patch to an existing installation, and you don't want files to be installed that the user didn't already have.
http://www.jrsoftware.org/ishelp/index.php?topic=filessection

Execute script once before installing a directory tree

I am trying to write an Inno Setup installer to install and then run other installers. The problem I have is when trying to install Cygwin. I have downloaded Cygwin and all packages I need so I can perform a local install. Then I want to add extra files and directories to the Cygwin installation.
My first attempt was like this:
[Files]
Source: "{#Cygwin}\Cygwin\*"; DestDir: {tmp}\cygwin; Flags: recursesubdirs;
Source: "{#Cygwin}\additional\*"; DestDir: {tmp}\cygwin\additional; Flags: recursesubdirs
[Run]
Filename: "{tmp}\cygwin\setup-x86_64.exe"; Parameters: "-q -L"; WorkingDir: "{tmp}";
But this means that I must have a script to add the additional files because there is nowhere to put them until Cygwin is actually installed by the command in the [Run] section.
I have tried using a BeforeInstall script in the [Files] section to run the Cygwin installer before adding the additional files, but because I have to use a wildcard with Source: "{#Cygwin}\additional\*"; the script is called once for every file in the directory tree.
The [Files] section of Inno Setup seems to only accept source files, and not a source directory, unless the directory has a wildcard.
Is there a way I can make it install everything from a directory tree without using a wildcard, or is there a way I can make the BeforeInstall script run just once, regardless of how many files are copied?
Install the Cygwin on the first call to BeforeInstall function only.
var
CygwinInstalled: Boolean;
procedure MyBeforeInstall;
begin
if CygwinInstalled then
begin
Log('Cygwin installed already');
end
else
begin
Log('Installing Cygwin');
{ install Cygwin here }
CygwinInstalled := true;
end;
end;

Inno Setup - How to execute MSI between 32 and 64 architectures

im trying to run 2 msi files for 32 and 64 bits from a third party and i am having a little trouble with the msi for 32bits windows architectures.
It seems the program extracts quite well the file but it doesn´t execute the installer. In the other hand for 64bits windows architectures the installer works. I don´t know where is the problem. Is there anything wrong with my code that im not seeing?Thank you!
[Setup]
...
ArchitecturesInstallIn64BitMode=x64
[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "filex64.msi"; DestName: "file.msi"; DestDir: "{app}"; Flags: deleteafterinstall; Check: Is64BitInstallMode
Source: "filex32.msi"; DestName: "file.msi"; DestDir: "{app}"; Flags: deleteafterinstall; Check: not Is64BitInstallMode;
Source: "manual.pdf"; DestDir: "{userdesktop}"; DestName: "Manual.pdf"
[Run]
Filename: "{sys}\msiexec.exe"; Parameters: "/package ""{app}\file.msi"" /qn /norestart /passive"; Flags: shellexec waituntilterminated; StatusMsg: "A instalar software {#MyAppVersion}";
Filename: "{userdesktop}\Manual.pdf"; Flags: postinstall;
I figure it out.
Flags
32bit
Causes the {sys} constant to map to the 32-bit System directory when used in the Filename and WorkingDir parameters. This is the default behavior in a 32-bit mode install.
This flag cannot be combined with the shellexec flag.
64bit
Causes the {sys} constant to map to the 64-bit System directory when used in the Filename and WorkingDir parameters. This is the default behavior in a 64-bit mode install.
This flag can only be used when Setup is running on 64-bit Windows, otherwise an error will occur. On an installation supporting both 32- and 64-bit architectures, it is possible to avoid the error by adding a Check: IsWin64 parameter, which will cause the entry to be silently skipped when running on 32-bit Windows.
This flag cannot be combined with the shellexec flag.
Source:
http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_iswin64
Based on this, i changed my script ir order to pinpoint correctly the "msiexec.exe" file for both architectures. Thank you guys!
[Run]
Filename: "{sys}\msiexec.exe"; Parameters: "/package ""{userdesktop}\Classic_Client_{#MyAppVersion}_64.msi"" /qn /norestart /passive"; Flags: 64bit skipifdoesntexist waituntilterminated; Check:IsWin64; StatusMsg: "A instalar Classic Client {#MyAppVersion} - 64bit";
Filename: "{sys}\msiexec.exe"; Parameters: "/package ""{userdesktop}\Classic_Client_{#MyAppVersion}_32.msi"" /qn /norestart /passive"; Flags: 32bit skipifdoesntexist waituntilterminated; StatusMsg: "A instalar Classic Client {#MyAppVersion} - 32bit";
the {sys} constant is the issue.
{sys} The system's System32 directory. For example: If you used
{sys}\CTL3D32.DLL on an entry and the system's Windows System
directory is "C:\WINDOWS\SYSTEM", Setup or Uninstall will translate it
to "C:\WINDOWS\SYSTEM\CTL3D32.DLL".
On 64-bit Windows, by default, the System32 path returned by this
constant maps to the directory containing 32-bit system files, just
like on 32-bit Windows. (This can be overridden by enabling 64-bit
mode.)

Rename an existing file before replacing it in an Inno setup

I've got the following script...
[Files]
Source: "extractor.prop"; DestDir: "{app}"
How can I say, if extractor.prop already exists, rename it to extractor.prop.old and install this one? By default at the moment it just deletes the old file so I don't want to erase the file if it's currently in use on a customer's site.
Use another [Files] entry with the external flag:
[Files]
Source: "{app}\extractor.prop"; DestDir: "{app}"; DestName: "extractor.prop.old"; Flags: external skipifsourcedoesntexist
This is what external does:
external
This flag instructs Inno Setup not to statically compile the
file specified by the Source parameter into the installation files,
but instead copy from an existing file on the distribution media or
the user's system. See the Source parameter description for more
information.
(source)

Resources