Deliver a file to all users profile programmatically

Discover(request) our samples to help you get started with your project.
Post Reply
Posts: 4441
Joined: Wed Apr 24, 2013 3:51 pm

Deliver a file to all users profile programmatically

Post by Dan » Mon Nov 26, 2018 2:39 pm


If your installer needs to install some files under each user profile, among the self-healing and active setup mechanism, there is always the custom actions approach.

In this thread will exemplify how to configure the installer to deliver a file under each user's profile (both registered and next users) using a .bat file. the content of the bat file can be something as follow:

Code: Select all

FOR /f "tokens=*" %%G in ('dir /b /a:d-s-l "%SystemDrive%\Users"') DO (
  IF /I NOT "%%G"=="Public" (
    IF NOT EXIST "%SystemDrive%\Users\%%G\AppData\Roaming\MyCompany\demoFile.config" md "%SystemDrive%\Users\%%G\AppData\Roaming\MyCompany"
    xcopy.exe %1 "%SystemDrive%\Users\%%G\AppData\Roaming\MyCompany" /C /I /Q /R /K /Y
Basically, the script loop through the folders in C:\Users excluding system folder. For each existing user, it will check the existence of the specified directory. If the sub-directory does not exist, it will be created and the config file will be copied at that location. For details, you can also check the xcopy article and How to launch a CMD or BAT file.

A very nice thing that the script does, is that it will copy the related config file under the Default profile. That means, any future created user on the machine will end having the config file under his profile. The Default user profile is used as a template when creating future users account on the machine.

Now, let's configure the project to implement this. For this case, I've created a demo installer that installs a shortcut to the Updater on the Desktop. It simply checks if a new version of Advanced Installer is available.

Since the config file will be copied by the .bat file, then you can add both bat file and config file as temporary files. You can read more about temp files in the Temporary Files Operations in the Files and Folders Page article.
temp files.PNG
temp files.PNG (11.43 KiB) Viewed 18745 times
To launch the .bat file, you can use the predefined launch file custom action:
ca props.PNG
ca props.PNG (43.91 KiB) Viewed 18745 times
Of course, you can use the VBScript or a PowerShell custom action to implement this functionality or create your custom action as a custom action written in C# or a custom action written in C++.

The sample project is attached to this thread, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.

Best regards,
Deliver file to all users
(55.16 KiB) Downloaded 455 times
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Post Reply