Fulgan
Posts: 101
Joined: Mon Feb 27, 2012 10:42 am

Custom action to try to lock a file in the destination folder (exclusive lock)

Hello,

I'm still struggling to try to find a foolproof way to deploy an application to a shared folder.

Background: our application can be deployed on a remote share and users simply receive a link to the mais entry point. The application is made of many executables and several common libraries.

Problem: When another user is running the application from one machine and someone attempts to install an update from another, the installation typically will fail (because the executable and associated libraries are locked). When this happen, the installer fails and, if the user choses to abandon the installation, it leaves the installation in an unusable state: some files will have been replaced by the new version, some will not.

In the past, we used to simply try to deploy one of the shared libraries used by ALL the executable first but it is impossible to do the same.

So, my next idea is to try to lock one of these files exclusively from an action that would be triggered after the installation GUI is run but before any file is copied.
I need to be able to do that from an MSI created with the Professional edition (14.5.2) of Advanced Installer (it's important for the package to be an MS, not an exe) and it must run on any OS down to Windows XP.

Any suggestion ?

Stephane
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action to try to lock a file in the destination folder (exclusive lock)

Hi Stephane,

Can you give me more details about the way you update your application? Normally, an upgrade uninstall all the old files first then install the new files, it does not replace the old files.

Also, I do not fully understand the solution that you want to implement. What do you mean by "lock one of these files"? Can you please give me more details?

Please take a look on the following threads which discuss how you can check if a file is in use or not:
https://stackoverflow.com/questions/876 ... -is-in-use
https://social.msdn.microsoft.com/Forum ... m=netfxbcl

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Fulgan
Posts: 101
Joined: Mon Feb 27, 2012 10:42 am

Re: Custom action to try to lock a file in the destination folder (exclusive lock)

Can you give me more details about the way you update your application? Normally, an upgrade uninstall all the old files first then install the new files, it does not replace the old files.
I'm not sure what you want to know about how the application is being deployed. The application is copied to the target directory and it's a very simple process (that's all it needs, really).

My problem is when the user decides to deploy on a network drive and other users are using the application from the same drive at the moment of the installation.

The installer routine fails in that case: the application end up only half-installed: every executable or library up to the ones currently in use are replaced but the new ones but nothing after that point. Of course, since I can't control the order of deployment, I can't start with the central libraries to make sure they are properly replaced.
Also, I do not fully understand the solution that you want to implement. What do you mean by "lock one of these files"? Can you please give me more details?
The idea is to request an exclusive write lock like this on one of the dlls that are used by all the executables before starting the installation process:

Code: Select all

CreateFile(PChar(AFile), GENERIC_WRITE or GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , 0)
If that fails, the installation is sure to fail.
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action to try to lock a file in the destination folder (exclusive lock)

Hi,

The reason I asked you about the way you update your application was that normally an update first uninstalls all the old files and then installs the new ones. The scenario you present is different, it looks like the old files are simply replaced one by one with the new files without being uninstalled first.
The installer routine fails in that case: the application end up only half-installed: every executable or library up to the ones currently in use are replaced but the new ones but nothing after that point. Of course, since I can't control the order of deployment, I can't start with the central libraries to make sure they are properly replaced.
The order the files are installed can be controlled from the "Table Editor" page, "File" table by manually modifying the "Sequence" value of the files. However, please make sure that there will not be two files with the same sequence value.
The idea is to request an exclusive write lock like this on one of the dlls that are used by all the executables before starting the installation process:
To achieve this, you can create a custom action that tries to lock a DLL file and sets a property if it succeeded. If it did not succeed, you can block the installation through a "Display error message" custom action or through a custom launch condition.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Fulgan
Posts: 101
Joined: Mon Feb 27, 2012 10:42 am

Re: Custom action to try to lock a file in the destination folder (exclusive lock)

The order the files are installed can be controlled from the "Table Editor" page, "File" table by manually modifying the "Sequence" value of the files. However, please make sure that there will not be two files with the same sequence value.
The table editor is not available on the professional edition (which is what is installed on the build machine).

I did try that solution already, however, but any attempt at manipulating the sequence number resulted in an error during installation (file not found, if memory serves).
Also, all the fiels are dynamically added to the installer by the build script: I really can't touch it.
To achieve this, you can create a custom action that tries to lock a DLL file and sets a property if it succeeded. If it did not succeed, you can block the installation through a "Display error message" custom action or through a custom launch condition.
I will see if I can write that. Thanks
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Custom action to try to lock a file in the destination folder (exclusive lock)

Hi,

Indeed, changing the files sequence number does not work when files are archived into CAB files, however this works if the LZMA compression method is selected in the "Builds" page.

Just let me know if there is anything else that I can help you with.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”