After discovering that my Windows Installer package was not correctly setting the InstallLocation value in the registry, I sought to correct it using Visual Studio.
My first reaction was to just set the registry entry myself using the Registry view in the Visual Studio Setup and Deployment project, however the MSDN documentation showed me that the correct way to do it is to use the ARPINSTALLLOCATION property in the installer package. Yet it can’t be a simple property that you set up front as an initial property. It has to be set after the user selects the destination directory. Therefore, it has to be set with a custom action in a proper place in the execution sequence. Unfortunately, you can’t create a simple type 51 custom action using Visual Studio. You can only include an Installer class written in C# or VB that is compiled in your solution. In my research, I discovered a convenient way to add the custom action after the MSI package is built using VB script. Here is the process that I went through:
I added a post build event to the setup and deployment project with the following
cscript "$(ProjectDir)SetArpInstallLocation.vbs" "$(BuiltOuputPath)"
I added the script SetArpInstallLocation.vbs to the deployment project folder. I got this script from the following blog article which was helpful in accomplishing this task.
After building the install package, I checked the program database using Orca.
In the CustomAction table there should be a SetARPINSTALLLOCATION
action with a source of ARPINSTALLLOCATION
and a target of [TARGETDIR]
Also the InstallExecuteSequence table should have a SetARPINSTALLLOCATION
action with a condition of NOT Installed
.
I installed the application and found that the registry entry was indeed created in the following location
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{guid}
Your results may vary!
[…] evitare di modificare il file MSI a mano con il tool ORCA, è possibile seguire i suggerimenti in questo post, sfruttando lo script VBS disponibile qui. In generale, non è male l’idea di usare uno script […]
Hi Robert ,
am getting this error when building setup project or am i missing anything….
‘PostBuildEvent’ failed with error code ‘1’ ‘Unspecified error’
I just copy pasted the cscript which you have mentioned.
Please guide.
Click the ‘…’ next to post build event in properties, you can click on ‘macros’ to see that $(ProjectDir) refers to the project directory for your solution. This is where you place the script. I suspect you placed it in the release folder.
sry, to add again, that vbs file which youve pointed not found.
If the script is not found, try here: https://robertbigec.wordpress.com/2012/09/10/vb-script-for-setting-the-installlocation-registry-entry/
I was wondering if you ever considered changing the page layout of your website?
Its very well written; I love what youve got to say. But maybe you
could a little more in the way of content so people
could connect with it better. Youve got an awful lot of text for
only having one or 2 pictures. Maybe you could space it out
better?
[…] evitare di modificare il file MSI a mano con il tool ORCA, è possibile seguire i suggerimenti in questo post, sfruttando lo script VBS disponibile qui. In generale, non è male l’idea di usare uno script […]