syn3rgy
Posts: 3
Joined: Wed Apr 22, 2020 11:35 am

Custom Action - Failing on Batch File

Tue Jul 06, 2021 9:45 am

Hi,

I am having an issue launching a batch file with a custom action. I have seen some other post but does not seem to resolve my issue.

This is a simple msi that drops some profile configuration files into the following location:
C:\Users\%UserName%\AppData\Roaming\OpenVPN Connect\profiles

So far, I have done the following:

In Install Parameters I have defined the property
"User_VPN_Profile" with a value of "C:\Users\%UserName%\AppData\Roaming\OpenVPN Connect\profiles"

In Instillation Folders > Application Folder, this points to [User_VPN_Profile]

In Files and Folders I created a new property based folder > User Defined > and pointed this to [User_VPN_Profile]
Dropped all the files i require to go to this location info that folder.

Test the install and it installs (Copies) the files to the correct location. ("C:\Users\%UserName%\AppData\Roaming\OpenVPN Connect\profiles")

I then created a "Custom Action > Launch File" and put this at the end of the "Install Execution Stage"
The batch file to run is location with the other files in the user roaming profile called "InstallProfile.bat"

The batch file contains the following:

Code: Select all

@ECHO OFF
"C:\Program Files\OpenVPN Connect\OpenVPNConnect.exe" --import-profile="C:\Users\%UserName%\AppData\Roaming\OpenVPN Connect\profiles\VPN AEC.ovpn" --username=ENTER_USERNAME
In the LaunchFile custom property i set:
File to lauch > [#InstallProfile.bat]
Working Directory > "[User_VPN_Profile]" (Tried with "" and without)
Execution time > immediately (also tried deferred)

I cant quite fathom what I am doing wrong. if i set it to run as administrator in the custom action, the install does not fail however, the batch file needs to run under user context as the profile need to be installed from >%Username% of the user.

Any help would be greatly appreciated.

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action - Failing on Batch File

Tue Jul 06, 2021 5:05 pm

Hello,

I have tested your scenario and I could indeed replicate the behavior.

To be fully honest with you, I am not quite sure why this is happening. If I were to assume, I would say the problem relies in the fact that maybe our custom action can not expand the %UserName% variable.

However, the good news is the fact that there is a much easier method which we can use to achieve what you need.

First of all, we do not need to complicate our lives with property based folders, setting properties, etc.

We can simply replicate the folder structure you need in "Files and Folders" page, i.e.:
AppData.png
AppData.png (55.25KiB)Viewed 7146 times

After the installation, the "test.bat" will be installed in the following location (on my machine):

"C:\Users\Catalin\AppData\Roaming\OpenVPN Connect\profiles\test.bat"

After doing so, all we need to do is to create the "Launch File" custom action, i.e.:
LaunchFile.png
LaunchFile.png (98.16KiB)Viewed 7146 times


As you can see, the custom action should be scheduled after the "Add resources" action group and with its' "Execution Time" set to "When the system is being modified (deferred)".

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

syn3rgy
Posts: 3
Joined: Wed Apr 22, 2020 11:35 am

Re: Custom Action - Failing on Batch File

Wed Jul 07, 2021 8:58 am

Hi Catalin

Thank you for the response. How did you create the User folder as i cannot create the folder at top level and do not have the option to create a regular folder only a property based one. That User folder also does not exist by default.


Image

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action - Failing on Batch File

Wed Jul 07, 2021 2:04 pm

Hello,

The "User Profile" folder has been recently added as per our user's requests (I believe it was added in version 18.1).

Previously, we had an article explaining how to do that:

How to install files in a custom folder

(third point)

In your case, however, I believe it should be enough just recreating the folder structure under the "Application Data" folder.

As per our Paths of the folders in the "Files and Folders" Page article, the "Application Data" folder will be resolved at install time to:
C:\Users\<username>\AppData\Roaming on Vista or above
Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”