Lexy
Posts: 8
Joined: Mon Oct 25, 2021 4:40 pm

Files in Use & Reboot prompt when accessing files

Fri Oct 28, 2022 10:55 am

We've got an application that installs 2 services.
I've recently tried to add a step in the upgrade process that manually backs up parts of the application folder, suffixing it with the previous version numbers.
No matter what I do or where I place the "Copy Folder" custom action (which was obviously before Remove Resources step), before InstallValidate or after it, I get the "Files in Use" dialog and a prompt to stop the running services. If I refuse to close the applications, the app prompts me to restart the computer after the installation.
Which has never been the case without this copy files action.

I've rewritten the custom action from PowerShell to VBScript, copied the files outside the application folder, placed the action before or after InstallValidate, or even as a client action on pressing the Next > button before VerifyReadyDialog.
It's all the same - files in use by the services, so close them, or I'll reboot the computer.

The services are certainly stopped during the installation to get them updated properly, and this step hasn't gone anywhere. It's also a PowerShell Custom action that does

Code: Select all

$instanceName = AI_GetMsiProperty INSTANCE_NAME
Get-Service svc1_$instanceName | % {Stop-Service $_}
Get-Service svc2_$instanceName | % {Stop-Service $_}
What helped to some extent is the Stop Service custom action.
However, if I place two Stop Service actions in the Install Execution Stage, only the first of them gets executed. If I reorder them then the other service gets stopped and the first one keeps running by the InstallValidate stage.

The code is simple:

Code: Select all

DetectService1 / Service name: svc1_[INSTANCE_NAME]
StopService / Service name: svc1_[INSTANCE_NAME] / Condition AI_SERVICE_STATE = "Started"
DetectService2 / Service name: svc2_[INSTANCE_NAME]
StopService / Service name: svc2_[INSTANCE_NAME] / Condition AI_SERVICE_STATE = "Started"
But it looks like it doesn't detect that the 2nd service is running. I've checked many times, it is running.
I even tried saving the AI_SERVICE_STATE into another property, but no dice.

And the log shows it:

Code: Select all

MSI (s) (78:04) [19:08:30:155]: Doing action: DetectService1
Action start 19:08:30: DetectService1.
MSI (s) (78:78) [19:08:30:157]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI6260.tmp, Entrypoint: DetectService
MSI (s) (78!D0) [19:08:30:161]: PROPERTY CHANGE: Adding AI_SERVICE_STATE property. Its value is 'Stopped'.
MSI (s) (78!D0) [19:08:30:161]: PROPERTY CHANGE: Modifying AI_SERVICE_STATE property. Its current value is 'Stopped'. Its new value: 'Started'.
Action ended 19:08:30: DetectService1. Return value 1.
MSI (s) (78:04) [19:08:30:163]: Doing action: RememberSvc1State
Action start 19:08:30: RememberSvc1State.
MSI (s) (78:04) [19:08:30:164]: PROPERTY CHANGE: Adding AI_SERVICE_STATE_1 property. Its value is 'Started'.
Action ended 19:08:30: RememberSvc1State. Return value 1.
MSI (s) (78:04) [19:08:30:164]: Doing action: AI_DATA_SETTER_27
Action start 19:08:30: AI_DATA_SETTER_27.
MSI (s) (78:04) [19:08:30:164]: PROPERTY CHANGE: Modifying CustomActionData property. Its current value is 'svc1_MyInstance'. Its new value: 'svc2_MyInstance'.
Action ended 19:08:30: AI_DATA_SETTER_27. Return value 1.
MSI (s) (78:04) [19:08:30:164]: Doing action: AI_DATA_SETTER_39
Action start 19:08:30: AI_DATA_SETTER_39.
MSI (s) (78:04) [19:08:30:165]: PROPERTY CHANGE: Modifying CustomActionData property. Its current value is 'svc2_MyInstance'. Its new value: 'svc1_MyInstance'.
Action ended 19:08:30: AI_DATA_SETTER_39. Return value 1.
MSI (s) (78:04) [19:08:30:165]: Doing action: StopService1
Action start 19:08:30: StopService1.
MSI (s) (78:E0) [19:08:30:166]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI6261.tmp, Entrypoint: StopWinService
Action ended 19:08:30: StopService1. Return value 1.
MSI (s) (78:04) [19:08:30:696]: Doing action: DetectService2
Action start 19:08:30: DetectService2.
MSI (s) (78:F0) [19:08:30:698]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI6476.tmp, Entrypoint: DetectService
MSI (s) (78!7C) [19:08:30:701]: PROPERTY CHANGE: Modifying AI_SERVICE_STATE property. Its current value is 'Started'. Its new value: 'Stopped'.
Action ended 19:08:30: DetectService2. Return value 1.
MSI (s) (78:04) [19:08:30:703]: Doing action: RememberSvc2State
Action start 19:08:30: RememberSvc2State.
MSI (s) (78:04) [19:08:30:703]: PROPERTY CHANGE: Adding AI_SERVICE_STATE_2 property. Its value is 'Stopped'.
Action ended 19:08:30: RememberSvc2State. Return value 1.
MSI (s) (78:04) [19:08:30:703]: Skipping action: AI_DATA_SETTER_37 (condition is false)
MSI (s) (78:04) [19:08:30:703]: Skipping action: StopService2 (condition is false)
MSI (s) (78:04) [19:08:30:703]: Skipping action: AI_DOWNGRADE (condition is false)
My last resort was to upgrade from AI 19.5 to the latest and greatest 20.0, but it didn't change anything.

Ple-a-se help.

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

Re: Files in Use & Reboot prompt when accessing files

Thu Nov 03, 2022 2:40 pm

Hello Lexy,

First of all, please note that the "FileInUse" dialog is not proprietary to us, but rather to the Windows Installer technology.

Now, it is quite clear that one of your services is keeping the files you are trying to copy in use and therefore the custom action fails.

The solution is, as you mentioned, to stop the service. From what I understand here, the problem is the fact that one of your service is not stopped if you use two custom actions one after another.

What I would do here to further investigate it, is place a "MessageBox" custom action after the second "DetectService" custom action to see what value the AI_SERVICE_STATE property holds. Perhaps it's not the expected value.

For instance, if you leave the condition blank for the second "Stop Service" custom action, does it work - i.e. is the service stopped?

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

Lexy
Posts: 8
Joined: Mon Oct 25, 2021 4:40 pm

Re: Files in Use & Reboot prompt when accessing files

Mon Nov 07, 2022 8:06 am

Thank you, Catalin,
it is quite clear that one of your services is keeping the files you are trying to copy in use and therefore the custom action fails.
Well, first of all, the custom action just reads the files, so even the running service doesn't keep them in use. I can copy the files from this folder while the service is running with no issues.

Besides, I did stop the services in a PowerShell custom action.
What I would do here to further investigate it, is place a "MessageBox" custom action after the second "DetectService" custom action to see what value the AI_SERVICE_STATE property holds. Perhaps it's not the expected value.
You can see from the logs that it's exactly the case. AI_SERVICE_STATE holds the value of the first service and somehow updates this value when I stop the service.
The status of the second service when I run the Detect Service action is not saved into AI_SERVICE_STATE properly somehow.

For instance, if you leave the condition blank for the second "Stop Service" custom action, does it work - i.e. is the service stopped?
If I leave the condition blank for the second Stop Service custom action, it works if the services are running, but if any of the services are stopped at the time of running the Stop Service action, the action fails.

I mitigated this by not failing the installer when the Stop Service action fails, but I still think there might be an issue with the Detect Service step.

Lexy
Posts: 8
Joined: Mon Oct 25, 2021 4:40 pm

Re: Files in Use & Reboot prompt when accessing files

Mon Nov 07, 2022 8:07 am

What I would do here to further investigate it, is place a "MessageBox" custom action after the second "DetectService" custom action to see what value the AI_SERVICE_STATE property holds. Perhaps it's not the expected value.
You are right, it's not the expected value. But why?

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

Re: Files in Use & Reboot prompt when accessing files

Tue Nov 08, 2022 3:39 pm

Hello Lexxy,

I remembered I have faced this issue in the past as well, that's why I asked you to check the value of the AI_SERVICE_STATE property.

You can read more about it here:

Using DetectService multiple services

where you can also find the workaround.

It seems like this is a limitation of this support.

Hope the workaround helps!

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

Lexy
Posts: 8
Joined: Mon Oct 25, 2021 4:40 pm

Re: Files in Use & Reboot prompt when accessing files

Mon Nov 14, 2022 4:07 am

Hi Catalin,

Thank you for your response.

I did read this thread before posting mine, but for some reason unknown to me, even when I save the AI_SERVICE_STATE property value to another property, it maintains the status of the first service detected.

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

Re: Files in Use & Reboot prompt when accessing files

Tue Nov 15, 2022 4:39 pm

Hello Lexy,

This is quite strange - as you can see, the user from that topic confirmed it worked.

Could you please give me some more details about how you implemented this (perhaps a screenshot of your "Custom Actions" page)?

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

Lexy
Posts: 8
Joined: Mon Oct 25, 2021 4:40 pm

Re: Files in Use & Reboot prompt when accessing files

Sat Nov 19, 2022 12:17 pm

Like this, for example:
Image
Image

Also tried with intermediate action to save the state:
Image
Image

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

Re: Files in Use & Reboot prompt when accessing files

Tue Nov 22, 2022 11:41 am

Hello,

I've just reread this entire thread and I might have gotten your scenario wrong.

In the thread I've given you above, the issue was actually the fact that the property value was overwritten from the second "Detect Service" custom action.

In your case, you are saying that the value is not overwritten (i.e. has the same value)? In order to correctly evaluate this, please make sure that the two services actually have a different state (i.e. one is stopped, one is running) otherwise it has no point, because if both services have the same state, the property will have the same value.

Could you please try the above and let me know the outcome?

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

Return to “Common Problems”