leeottaway
Posts: 4
Joined: Fri Sep 07, 2018 8:50 am

Detecting and stopping a service with wildcards

Wed Jun 23, 2021 1:16 pm

Hi

Over the years we have installed our servuice on different pc's with slightly different names. The name always begins with "Sign-IT". is there a way to detect if a service is running that starts with that name or does it have to be the exact name.....in which case it can never work for us.....

Lee

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

Re: Detecting and stopping a service with wildcards

Wed Jun 23, 2021 3:39 pm

Hello Lee,

Unfortunately, the predefined "Detect Service" custom action does not allow the use of wildcards.

However, we can create our own custom action that does that. For instance, we can use a PowerShell script and the "Run PowerShell Inline Script" custom action.

In order to get the status of a service using wildcards in PowerShell, we can proceed as it follows (the example give here is for the Windows Update service - wuauserv):

Code: Select all

$serviceStatus = (Get-Service wuaus*).Status
serviceStatus.png
serviceStatus.png (51.86KiB)Viewed 5614 times

We can then use the $serviceStatus variable to set an installer property, similar to our predefined custom action that sets the AI_SERVICE_STATUS property, e.g.:

Code: Select all

$serviceStatus = (Get-Service wuaus*).Status

AI_SetMsiProperty MY_SERVICE_STATUS $serviceStatus

Hope this helps!

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

leeottaway
Posts: 4
Joined: Fri Sep 07, 2018 8:50 am

Re: Detecting and stopping a service with wildcards

Wed Jun 23, 2021 3:58 pm

That does indeed help. Many thanks Catalin.

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

Re: Detecting and stopping a service with wildcards

Wed Jun 23, 2021 4:01 pm

You are always welcome, Lee!

I am glad it helped.

Please let me know if there is anything else I could help you with.

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

Return to “Common Problems”