MSI INSTALLDIR as custom action argument parameter value

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: 5.8.202
Operating system: W10 21H2
PowerShell version(s): 5

*** Please add details and screenshots as needed below. ***

Hello,
I'm trying to compile an MSI with custom actions and I'm wondering how to call INSTALLDIR as an argument parameter value. The below argument fails to compile. I have tried encapsulating INSTALLDIR in double quotes too, but also fails on compile. Is there some other way to accomplish this dynamically? Do I need to call the full path manually (C:\Program Files\Company\Product)?
  1. -Action Modify -Wallpaper -OOBE -ProfilePicture -BrandingSource INSTALLDIR
msi_custom_action.png
msi_custom_action.png (101.84 KiB) Viewed 4761 times
Compile error:
....heatout.wix(545) : error CNDL0104 : Not a valid source file; detail: The 'Product' start tag on line 4 position 4 does not match the end tag of 'Directory'. Line 545, position 4.
msi_compile_error.png
msi_compile_error.png (61.03 KiB) Viewed 4761 times
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: MSI INSTALLDIR as custom action argument parameter value

Post by Alexander Riedel »

The easiest way might be to not pass it as a parameter. The install folder *should* be the current folder when that runs.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

Re: MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

What about a not easy way? Is there a way to pass the value dynamically?
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

Re: MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

Ok, since I haven't gotten a a reply, I went ahead and made the default value the runtime path via:

Code: Select all

[String]$BrandingSource = (Split-Path -Parent $MyInvocation.MyCommand.Path)
The MSI compiles but I get an error that the [-Action] parameter cannot be found during install. How do I resolve this error?:

msi_install_error.png
msi_install_error.png (128.41 KiB) Viewed 4615 times

Additionally I have a few other issues.
  • 1. Cannot run the a new msi version over top an already installed msi with or without the version incremented.
    2. There does not seem to be any utility in the 'Maintenance' execution stage. What is considered maintenance? Initially I was thingking along the lines of a modify or repair option, but I only have uninstall action in programs and features.
    3. Is it possible to configure msi switches at all? if so, can the correlate to the custom actions?
I find the documentation on the msi packaging underwhelming. Is there an indepth article that covers these things? The blog post, youtube vid and and similar article covering the sample msi are not sufficent enough to understand how the packaging process works and the nuances. Just my two cents.

P.S. I still want to know if its possible to include a dynamic path parameter value in the custom action arguments.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: MSI INSTALLDIR as custom action argument parameter value

Post by Alexander Riedel »

The MSI "compile" as you call it, generates a standard Windows Installer file. MSI stands for MicroSoft Installer. There is plenty of MSI documentation on the Microsoft website. (https://docs.microsoft.com/en-us/window ... ler-portal)
This is not SAPIEN territory so to speak. We provide a tool to make simple MSI installers easy to generate. If you want the full depth of Windows Installer documentation
and how this works in detail, I would suggest to go to the source, which is Microsoft.

In order to help with issues like "Cannot run the a new msi version over top an already installed msi with or without the version incremented." we would need the underlying .psbuild file and an indication as what "Cannot run" means. I am assuming you get some kind of error message, but I wouldn't know from your post.

'Maintenance' is what is also referred to as 'Repair. Custom actions can be run on Install, Uninstall or Maintenance. Most of the terms used stem from the documentation of the WiX Toolset, which is the underlying mechanism for creating MSI files. There is excessive documentation here: https://wixtoolset.org/
I should point out that we only use and support a subset of the WiX Toolset in order to maintain a manageable simplicity.

I don't know what you mean by "configure msi switches". You start the MSI with any switches Windows Installer supports. https://docs.microsoft.com/en-us/window ... ds/msiexec.
If you are asking if you can modify the current MSI's properties in a custom action that uses an external script or executable in another process, no, you cannot.

As for the -Action parameter error, your post simply does not have enough information to venture a guess. It appears that you are running an external script which is missing a parameter. Without the .psbuild file and the actual script in question it is impossible to understand what you are trying to do.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

Re: MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

Thanks for that information, Alexander. What method should I use to securely and privately get you the files?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: MSI INSTALLDIR as custom action argument parameter value

Post by Alexander Riedel »

If you click on "Support" up top, you will find a link to upload support files.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: MSI INSTALLDIR as custom action argument parameter value

Post by Alexander Riedel »

I am not sure why you package the script as an executable to then only include the script rather then the executable in your MSI.
At first glance, the parameters look ok, except for brandingsource parameter.
That would not work in a packaged file or running from PowerShell Studio.
See https://www.sapien.com/blog/2009/09/02/ ... nvocation/

I also noticed that you mark your custom actions as "Run under system account", which is only required in some very special circumstances.
Since you already require admin privileges for the install, that is not necessary. Using the 'system account' setting would run the script not as a logged on user, which can have side effects, like a different working folder. I would turn that off.

As I cannot run your script or build the MSI here, that is about all I can see.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

Re: MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

I'm not actually packaging the script as an executable, which is why I am calling the script in the msi custom actions. As for execution as system, the users do not have access to modify resources the script is accessing. Requiring admin elevation is a requirement in our org. Additionally the script that runs requires system level access to complete all operations. I have thoroughly tested both manually and via build msi that execution as system is required.

I can see how $MyInvocation could be an issue when executed via MSI. I have updated the code to use the below. tested and working in an msi build:
  1. if (!($BrandingSource))
  2. {
  3.     if ($HostInvocation -ne $null)
  4.     {
  5.         $BrandingSource = Split-Path $HostInvocation.MyCommand.Path
  6.     }
  7.     else
  8.     {
  9.         $BrandingSource = Split-Path $MyInvocation.MyCommand.Path
  10.     }
  11. }

The issue with the [-Action] parameter persists after building as an msi. After some initial frustration I opened up the msi in Orca. I can see the parameters show correctly, but are wrapped in double quotes. The parameter string should not be wrapped in double quotes. I edited the msi in Orca and removed the double quotes around the custom action script parameters. I have been testing code/msi build revisions the last week and change using this method, editing the msi custom action values after each build. Seems like there is a bug in the msi build process adding the double quotes.

Default config after build - not working:
msi_custsom_action_build.png
msi_custsom_action_build.png (145.48 KiB) Viewed 3714 times

Edited config - working:
msi_custsom_action_build_edit.png
msi_custsom_action_build_edit.png (130.7 KiB) Viewed 3714 times

After a fresh msi build you can see the difference in the output vs the msi build sheet:
msi_custsom_action_comparison.png
msi_custsom_action_comparison.png (551.56 KiB) Viewed 3714 times
As an aside, I'd like to see an option added to the msi custom action config added to allow the script to be executed in a hidden window so its not visible to the user. I could edit the msi custom action powershell.exe parameters but this is less than ideal. Does this option currently exist and I've overlooked it?
Last edited by funkymonkey on Wed Jun 29, 2022 8:04 am, edited 1 time in total.
User avatar
funkymonkey
Posts: 9
Last visit: Wed Jan 11, 2023 8:57 am

Re: MSI INSTALLDIR as custom action argument parameter value

Post by funkymonkey »

Other issue with the MSI:
1. When executing the msi to modify/repair or remove, the only option present is "Remove". How do I enable the other options?
msi_remove_only.png
msi_remove_only.png (55.79 KiB) Viewed 3714 times

2. After clicking remove on the image above I get an error about needing PS v5. PS 5 is already installed. The msi uninstalls without issue when I run msiexec /x"{B6311FFA-C9EB-416F-BCD3-14E7415C710B}" for example
msi_remove_error.png
msi_remove_error.png (57.63 KiB) Viewed 3714 times

3. Occasionally I'll get an error executing the msi when another version is installed. It doesn't happen all the time, I'm not sure what causes the error to occur.
msi_install_version_error.png
msi_install_version_error.png (55.69 KiB) Viewed 3714 times
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.