PDA

View Full Version : Uninstalling services



mikedoris
09-16-2009, 04:18 AM
Hi,
I've got what looks like a race condition or something like it and I'm sure its down to the way that the SCM (Service control manager works). I install a service using the following code within an sbi :

! Stop and remove service to cope with case where service is still installed from a failed uninstall.
Stop Service "IncaCfgBackup"
Remove Service "IncaCfgBackup"

Install File "[SB_PROJECT]\..\CfgBackup\x64\Release\CfgBackupGUI.exe" to "%_SB_INSTALLDIR%\CfgBackupGUI.exe" (Always Install)
Install File "[SB_PROJECT]\..\CfgBackup\x64\Release\CfgBackup.exe" to "%_SB_INSTALLDIR%\CfgBackup.exe" (Always Install)

Create Service "IncaCfgBackup" (Always Install)
Start Service "IncaCfgBackup"

When the user removes the installation using Add/Remove programs they receive the message "The following file is in use and cannot be updated". If you hit retry it continues without any issue. This leads me to believe that a request to the SCM to stop the service is issued followed by the uninstall attempting to remove the file. The uninstall request into the SCM must be asynchronous and hasn't completed by the time we try to remove the binary.

Has anyone any advice with regards to working around this. If I unistall silently the user will always have to reboot which isn't ideal.

Thanks,

Mike

linder
09-16-2009, 04:23 AM
Mike,

I would suggest to develop a custom uninstall that tries to stop and remove the service before the uninstall application removes the service file(s).

Does this help?

Friedrich