Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

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 SUBSCRIPTION NUMBERS, LICENSE 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.
arbitmcdonald
Posts: 7
Joined: Fri Jan 25, 2019 4:43 pm

Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by arbitmcdonald » Thu Aug 22, 2019 8:07 am

To help you better we need some information from you.

*** 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:
32 or 64 bit version of product: 64-bit
Operating system: Windows 10 Pro
32 or 64 bit OS: 64-bit

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

I have created a Windows Service which works perfectly, PS Studio made this a lot easier. The only issue I have at the moment is that I need to capture a value from the user as part of the installation and save the value to the registry. The 'Use a simple UI when installing' checkbox is a dream and makes the installer creation and package itself very professional and simple to use, but it really is a simply UI with no configuration or branding options.

Image

When I run the MSI without any custom actions everything works as expected, but because I didn't collect a vital value from the user the service itself is useless.

To collect the ID I have created a custom action which runs Install.exe (which is a 'compiled' .ps1 script that prompts for a value in a small window and writes to the registry). Unfortunately the service's MSI is run as administrator but Install.exe is not inheriting these elevated permissions, and so it fails to write to the registry and the install process fails.

The EXE also has a manifest to require elevation.

How can I get the EXE (which collects the ID from the user) to run with elevated permissions, when it is being triggered as a custom action by the MSI which is aleady running with elevated permissions?

Image
Image

One important note is that if I run Install.exe manually rather than as a custom action, it requests elevation and works perfectly. Both components works perfectly in isolation, but together it fails.

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by Alexander Riedel » Thu Aug 22, 2019 9:02 am

I am not at liberty to test this at the moment, but in general, given your settings, your custom action should be running elevated. Given that it does not prompt supports that, since there is no elevation prompt for something that is already elevated.
Which exact part of the registry are you trying to write to?
Alexander Riedel
SAPIEN Technologies, Inc.

arbitmcdonald
Posts: 7
Joined: Fri Jan 25, 2019 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by arbitmcdonald » Thu Aug 22, 2019 9:53 am

Hi Alexander, thanks for your response. It is writing to HKLM:\Software. I'm creating a new key (HKLM:\Software\CustomKey) and then writing the DWORD value to it.

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by Alexander Riedel » Thu Aug 22, 2019 9:57 am

A bit more specific please. I am assuming some sub key. Does that already exist?
Alexander Riedel
SAPIEN Technologies, Inc.

arbitmcdonald
Posts: 7
Joined: Fri Jan 25, 2019 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by arbitmcdonald » Thu Aug 22, 2019 9:59 am

Code: Select all


New-Item –Path "HKLM:\SOFTWARE" –Name SomeKey -Force -ErrorAction Stop
New-ItemProperty -Path "HKLM:\SOFTWARE\SomeKey" -Name "SomeName1" -Value $SomeVal1  -PropertyType "String" -Force -ErrorAction Stop
New-ItemProperty -Path "HKLM:\SOFTWARE\SomeKey" -Name "SomeName2" -Value $SomeVal2  -PropertyType "String" -Force -ErrorAction Stop
		

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by Alexander Riedel » Thu Aug 22, 2019 10:12 am

Ok, I guess that means this is classified :D
At any rate, any error checking to determine WHY it fails?
Or to verify it actually gets called?
Alexander Riedel
SAPIEN Technologies, Inc.

arbitmcdonald
Posts: 7
Joined: Fri Jan 25, 2019 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by arbitmcdonald » Fri Aug 30, 2019 2:59 pm

Sorry for not coming back to you sooner, I was away on holiday. I'm really grateful for your support but I've decided to go down the Wix Toolset route. I've created some custom dialogs with forms to collect this data am updating the registry cleanly use the MSI installer. I'm using PS Studio to create and sign the service executable and Wix to package and install.

Thanks again!

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by Alexander Riedel » Fri Aug 30, 2019 3:38 pm

Glad to hear you found a way to make it work. Just wanted to point out that we are using the WiX toolset to build the MSI.
Just wondering what would be different.
Alexander Riedel
SAPIEN Technologies, Inc.

arbitmcdonald
Posts: 7
Joined: Fri Jan 25, 2019 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by arbitmcdonald » Sat Aug 31, 2019 4:32 am

Full control over dialog content, dialog order, UI design and all other customisation etc. The features for 'compiling' in Studio are great if you need a basic installer without any questions asked. It seems highly limited in its options currently?

User avatar
Alexander Riedel
Posts: 7098
Joined: Tue May 29, 2007 4:43 pm

Re: Windows Service MSI Installer - Custom action (EXE) not running with elevated permissions

Post by Alexander Riedel » Sat Aug 31, 2019 4:52 am

Well, yeah, we keep it simpler on purpose.
I was referring to the custom actions setting the registry keys.
I did a little test in the meantime now and I was having no problem setting registry entries in a custom action.
Alexander Riedel
SAPIEN Technologies, Inc.