CharlesAnthony
Posts: 18
Joined: Wed Oct 07, 2009 9:45 am

Stopping Service as part of Uninstall

Hi,

Further to my last question here http://www.advancedinstaller.com/forums ... =2&t=11259 , I also wish to stop a service before running the uninstall, in order to prevent the reboot.

Again, I need this to happen *before* InstallValidate, and I can't rely on the "FilesInUse" and "MsiRMFilesInUse" dialogs, because I am running without a GUI (/passive).

This needs to run on Vista & Windows 7 (as well as XP), so I can't rely on the Service Control settings in AI (I've gathered this from http://www.advancedinstaller.com/forums ... ice#p28512)

The service is running as the local System Account - which means, to stop it, you need to be running elevated.

How can I run an Custom Action *before* InstallValidate to stop the service, where the custom action runs "elevated" ?

Cheers,

Charles.
Bogdan
Posts: 2794
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Stopping Service as part of Uninstall

Hi Charles,

Have you tried the custom action from the post you have mentioned? If it has worked for the previous user
then it should work in your case too.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
CharlesAnthony
Posts: 18
Joined: Wed Oct 07, 2009 9:45 am

Re: Stopping Service as part of Uninstall

Hi,

Yes, I have; it didn't work because

a) For some reason, it couldn't find the temporary file created to sleep (I got wscript.exe messagebox s saying that it couldn't find the temporary file). I took out the sleep, and just let it loop-until-service-stopped (consuming much CPU, but for a test, that was fine)
b) After a) The service couldn't be stopped.

I think the service can't be stopped because it is running as the local system account; to stop a service running as a system account, I believe you need to be running "elevated" - I tested that by trying at the command line. If I try and stop the service with "sc stop servicename" I get access denied. If I run the command line as administrator, it gets stopped.

So, from that, I deduce that you need be running elevated to stop the service - but you can't run as elevated until *after* InstallValidate.

Windows Installer *really* makes life difficult here - I have spent over 4 days looking at this!

I am currently at a loss to know how to proceed!

Kind Regards,

Charles.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Stopping Service as part of Uninstall

Hi Charles,

The elevation takes place as soon as InstallExecuteSequence starts. The installer is not elevated during UI, so make sure your custom action is placed under InstallExecuteSequence and you are correctly setting the Installation Type field from the Install Parameters page.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
CharlesAnthony
Posts: 18
Joined: Wed Oct 07, 2009 9:45 am

Re: Stopping Service as part of Uninstall

Hi,

The service needs to be stopped *before* InstallValidate (That's where the files-in-use check happens, yes?)
Elevation is needed to stop the service.
It is not possible to elevate before InstallValidate.

This appears to me to be an incredibly stupid thing (on Windows Installer's behalf, not AI's).

I've tried creating a workaround - I've created my own elevated "uninstall" program that stops the service, and then calls MSIEXEC /X {ProductCode} to remove my application. That works - except, I can't get Add/Remove Programs control panel applet to call my own uninstall program.

I *think* I have to change HKLM\SOFTWARE\Microsoft\Windows\Uninstall\[PRODUCTCODE]\UninstallString to be a call to my program AND HKLM\SOFTWARE\Microsoft\Windows\Uninstall\[PRODUCTCODE]\WindowsInstaller to be 0 (otherwise Add/Remove Programs ignores the UninstallString)

I have seen several places on the forums where you have said "create a custom action to call the reg command line utility" - and I just cannot work out how to do it! I have tried using "Launch FIle or Open URL", "Exe with working DIR" - and I am at a loss! I know that reg.exe is WINDOWS\System32, and that is the SystemFolder - I can't work the magic incation/combination to call the thing.

Is there an example anywhere of this being done (calling reg as a command line from a Custom Action)?

Regards,

Charles.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Stopping Service as part of Uninstall

Hi Charles,

Modifying that registry entry is not a solution because Windows Installer will revert it if it detects a problem with the installation. It's also reverted during a repair or modify process.

Since the uninstall process may not use a full UI, you can try creating an EXE which finds sc.exe and launches it with Administrator privileges in order to stop the service. This approach requires custom code for the EXE.

A simpler approach is to select "Force reboot after install" in the "Reboot Behavior" combo from "Install Parameters" page. This way Windows Installer can perform the uninstall and the service files are removed automatically after a reboot.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
CharlesAnthony
Posts: 18
Joined: Wed Oct 07, 2009 9:45 am

Re: Stopping Service as part of Uninstall

Hi,

I am trying to
a) Avoid any UI at all
b) Avoid a reboot

My current approach appears to be working :

a) I'm selecting "Do Not Show In List" on the Product Details tab - this means that the standard Windows Installer entry is hidden in "Add/Remove Programs" (registry entries are still there)
b) I'm creating my own Uninstall registry entries under HKLM\SOFTWARE\Microsoft\Windows\Uninstall\[PRODUCTNAME]\UninstallString; this entry appears under Add/Remove Programs
c) My own uninstall items call my own custom uninstall .exe which stops the service, then calls MSIEXEC /X [ProductCode]

(I found the ideas in this thread here http://www.pcreview.co.uk/forums/thread-1544595.php )

It's a hack, I'll grant you, but I can't see that there's much of an alternative.

Cheers,

Charles.

Return to “Common Problems”