DDi
Posts: 17
Joined: Tue Feb 25, 2014 1:22 pm

Another question about updating Windows Service without changing login details

I know already several topics exist about keeping service login details while performing an upgrade. I have a very similar (if not exactly the same) scenario as in these topics:

Windows service account and upgrades
Update service without changing its logon details

In my scenario I prefer NOT to use a custom action to delete the service when uninstalling (real uninstall, not uninstalling for upgrade). I thought I had a solution for this by:
  • Adding a 2nd Service Control Operation and attaching it to a different component (e.g. with only some dummy file or registry entry) than the 1st Service Control Operation (attached to the component that contains the Service file and "Service to install"-properties).
  • Configuring the 2nd Control Operation to stop and delete the service on uninstall.
  • Changing the 1st Control Operation to only stop the service on uninstall.
  • Configuring the component containing the 2nd Control Operation (In Package Definition > Organization) with the Condition "NOT UPGRADINGPRODUCTCODE"
The main problem is: this does not work :cry: but I do not understand why. When I add a condition to the component that always evaluates to false (e.g. "1 = 2"), it "works" i.e. it does not uninstall the service at all. During upgrade it keeps its login details. So it seems the problem lies in evaluating the condition "NOT UPGRADINGPRODUCTCODE" when checking whether the component must be (un)installed.

For testing purposes I added some custom actions right before/after the StopServices/DeleteServices actions in the Install Execution Stage that log and test (i.e. condition is e.g. "UPGRADINGPRODUCTCODE" or "NOT UPGRADINGPRODUCTCODE") for the value of UPGRADINGPRODUCTCODE. Using theses custom actions I see the custom actions get triggered just as I expect.

Can you explain why the condition on the component behaves differently than the conditions in these custom actions?

Regards,
Erik - DDi
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Another question about updating Windows Service without changing login details

Hello Erik,

I have tried testing this, but unfortunately I did not manage to get it working no matter what condition I used for the component assigned to the service control operation.

If possible, could you please forward me a sample project and a step by step test case so I can further investigate this on our end?

The way I got this working is by conditioning the "DeleteService" action in the "Table Editor" page --> "InstallExecuteSequence" table with the following condition:

Code: Select all

VersionNT AND (NOT UPGRADINGPRODUCTCODE)
Of course, in addition to this, you should also condition the component with the same condition (excepte the VersionNT part), so the service is removed upon uninstall.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DDi
Posts: 17
Joined: Tue Feb 25, 2014 1:22 pm

Re: Another question about updating Windows Service without changing login details

Hello Catalin,

I have just sent an email to support at advanced installer dot com.

The email contains a list of "steps to reproduce" and a link from where you can download a zip with AI projects and required resources.

Oops.... Something I forgot to mention: I am trying to find a solution without manually editing the Table Editor.

Thank you for investigating.
Erik - DDi
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Another question about updating Windows Service without changing login details

Hello Erik,

Please accept my apologies for the delayed reply.

I have answered you over the email.

Let's continue the thread there, please, as we can update this forum thread once we reach a solution.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DDi
Posts: 17
Joined: Tue Feb 25, 2014 1:22 pm

Re: Another question about updating Windows Service without changing login details

Hello Catalin,

No problem.

I still prefer a solution without the use of Custom Actions and Custom Table Editing, but for now I already implemented a solution using a Custom Action (using a attached native DLL) for service deletion on real uninstall, which seems to work fine (it is under testing ;) ). So no real rush needed.

However it still would be nice to know, why the condition "NOT UPGRADINGPRODUCTCODE" on a "Delete Service Component" does not work.

Best regards,
Erik - DDi
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Another question about updating Windows Service without changing login details

Hello Erik,

I am glad you guys managed to work this around.

This is currently under investigation on my side to see whether we can get rid of the Custom Action approach.

I will followup either here or on email when I'm done.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DDi
Posts: 17
Joined: Tue Feb 25, 2014 1:22 pm

Re: Another question about updating Windows Service without changing login details

Hello Catalin,

I hope you don't mind, that I share your solution (that you sent me by email) in this post, because I think it can help others as well.
Hello Erik,

As promised, here is my followup on this.

First of all, thank you for the provided resources, they were really useful in helping me reproduce the issue and further investigating this to find a solution.

As far as I tested this, a solution would be to condition the "DeleteService" standard action using the "NOT UPGRADINGPRODUCTCODE".

To do so, please proceed as it follows:

- go to "Custom Actions" page

- right click on any "Action Group" - i.e. "Add resources" --> "Show standard action" --> "Remove Resources" --> click on "DeleteService"

- in the "Condition field", beside what is already there, add the following:

AND (NOT UPGRADINGPRODUCTCODE)

The final result would be:

VersionNT AND (NOT UPGRADINGPRODUCTCODE)

This way, the service should no longer be removed upon upgrade and therefore the settings should be saved.

With your exact resources, I faced a problem on normal uninstall where the service is not removed, but I believe this is not related to the setup itself, but rather to the fact that the service can not be removed, because I tried manually deleting it using the "SC.EXE" tool and I could not remove it.

Hope this helps!
Best regards,
Catalin
Thank you very much for your solution. It surely is a very simple (and thus the best ;) ) solution for some of our setups.

FYI: I don't have any issues on normal uninstall myself. As far as I know SC.exe simply deletes the service registration from the registry and does not rely on Service.exe implementation.

Final question (I hope ;) ) in this post: in some of our setups, service registration is done in a Merge Module. In a Merge Module I cannot edit the condition field of the "DeleteService" standard action (it is disabled / read only). Am I correct that, if I would condition the "DeleteService" standard action in the aip for the msi, the condition will apply for all contained msm's?

Hoping to hear from you soon.

Thanks again for your help.

Best regards,
Erik - DDi
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Another question about updating Windows Service without changing login details

Hello Erik,
I hope you don't mind, that I share your solution (that you sent me by email) in this post, because I think it can help others as well.
For sure not. I was about to do the same once you confirmed that everything works as expected.

Since this was quite a requested topic, for me at least, in the past, I might even create a little article and post it in our "Sample Projects" subforum.

I am really glad the solution works as expected and that you guys are happy with it.
Final question (I hope ;) ) in this post: in some of our setups, service registration is done in a Merge Module. In a Merge Module I cannot edit the condition field of the "DeleteService" standard action (it is disabled / read only). Am I correct that, if I would condition the "DeleteService" standard action in the aip for the msi, the condition will apply for all contained msm's?
MSM files are basically additions to the default MSI database. They are merged into the main database at build time, meaning that if you have a service in your MSM, it would use the "DeleteService" standard action present in the main MSI package.

In fact, just to be sure of this, I ran a little test and I can confirm that this is the case.

One thing you guys should be careful about is the EXE of your service, because that will be deleted and even tho the service will stay in "services.msc" (you will be able to see it there), the service can not be started since its executable was removed.
CannotFindFileSpecified.png
CannotFindFileSpecified.png (184.56 KiB) Viewed 5216 times

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DDi
Posts: 17
Joined: Tue Feb 25, 2014 1:22 pm

Re: Another question about updating Windows Service without changing login details

Hi Catalin,

Thank you for checking the Merge Module behavior. Your information is really helpful.

Because we keep the service registration only while upgrading, I am not sure when a situation with a missing service.exe could occur. During the upgrade the service gets stopped, the service registration remains, the exe is replaced by a newer version and finally the service gets started again. If I am missing something "dangerous" here, please let me know.

There is one additional issue that popped up from our tests yesterday: on upgrade the config (i.e. everything on tab "Log On" and everything on tab "Recovery") of the service is unchanged ( :mrgreen: GREAT). However the Startup type still gets reset to the value from the msi. So if someone changed the Startup type to e.g. "Disabled" it will get reset to "Automatic" during upgrade in our scenario. I was planning to start a new topic for this, but since you're planning to create an article, please consider mentioning this behavior or (if possible) even provide a solution for this as well.

Thanks again.
Erik - DDi
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Another question about updating Windows Service without changing login details

Hello Erik,

You are always welcome!
Because we keep the service registration only while upgrading, I am not sure when a situation with a missing service.exe could occur. During the upgrade the service gets stopped, the service registration remains, the exe is replaced by a newer version and finally the service gets started again. If I am missing something "dangerous" here, please let me know.
Regarding this, you are completely right. I must have thoght of some other scenario here.
However the Startup type still gets reset to the value from the msi. So if someone changed the Startup type to e.g. "Disabled" it will get reset to "Automatic" during upgrade in our scenario.
Regarding this, as previously mentioned, that is a standard action (not proprietary to us), and I really can not say why only the "Startup type" would be reset.

If we want to not remove the service on uninstall, perhaps we should also condition the action we talked about above - that would be the "InstallServices" action - to not execute in the new package (i.e. when the new package is installed). We could make use of the OLDPRODUCTS property here, with the condition being something like:

Code: Select all

NOT OLDPRODUCTS
Hope this helps!

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

Return to “Common Problems”