nsSCM plugin tip
Hi,
Just wanted to share the solution to a very frustrating problem that has kept me busy for a while, I searched for old posts about this issue but found nothing, so here it is:
I'm working on an installer for a small win32 service application, and using the nsSCM plugin to install/start/stop the service.
So far it's all working fine on my PC system, however I did run into a problem when I tried to run the setup as an upgrade (service already installed and running) on a very slow VIA mini-ITX system. During the setup process the service should have been stopped so the service .exe can be overwritten with the new version, but appearantly this did not work properly.
The main section contains code that calls nsSCM and then installs the new files:
nsSCM::Stop /NOUNLOAD ${SERVICE_NAME}
...
File "bunch of files..."
File "bunch of files..."
File "bunch of files..."
File "name of service.exe"
Sometimes I would get a "File is locked/in use" or similar dialog for the service exe, however it worked when you would press "retry".
What I figured out is that the nsSCM::Stop command does not wait for the service process to fully terminate, which can take a few seconds on slow systems, depending on your application.
Solution:
I used the FindProcDLL plugin to wait for the process to terminate, not sure if this is the best way, but it works :)
nsSCM::Stop /NOUNLOAD "service name"
waitloop:
FindProcDLL::FindProc "service name.exe"
StrCmp $R0 1 0 waitdone
Sleep 500
goto waitloop
waitdone:
...
File "...
The same code should also be added to the uninstaller, otherwise the service exe might be locked when the uninstaller attempts to delete the file.
Just thought I'd share this approach, maybe it will be of use to someone ;)