I had the same problem as you. I have a system service that I want to uninstall and then reinstall as part of the update. On some systems, this will not work without a reboot. The problem was that the DeleteService () call would return to normal, but the next CreateService () call would tell me that the service still exists but was marked for deletion (error code 1072). The registry will reflect this because the subkey was still there (under HKLM \ System \ CurrentControlSet \ Services), but the "DeleteFlag" parameter was set to 1. From now on, only a reboot can fix the situation.
Some things that do not work:
- Using "sc delete": it had the same problems as me. The call will return to normal, but the service has not actually disappeared and is still in the registry using DeleteFlag = 1.
- Removing a key in the registry. The service manager seems to store the database in memory, and the registry is a copy of it for the next boot.
- Adding wait loops waiting for .exe files to be ready to overwrite, kill a process, etc.
- Closing service descriptors. Which of them?
But here is what worked:
In some articles in stackoverflow, I noticed that net.exe has start / stop functions (I only knew about sc.exe utility). And oddly enough, "net stop svcname" worked, plus "sc delete svcname"! Therefore net.exe should do what I am not doing.
But net.exe does not contain an import for ControlService (), so how to stop the service? I found out that net.exe starts net1.exe, but net1.exe does not import ControlService (). I used the great API Monitor utility ( http://www.rohitab.com/apimonitor ) to find out what net1.exe does, but it never called anything promising.
But then I saw that he was importing NetServiceControl () from NETAPI32.DLL (which had at least “Service” in his name!). MSDN says this feature is deprecated. However, I found a prototype in LMSvc.h and some parameter descriptions here: http://cyberkinetica.homeunix.net/os2tk45/srvfpgr/369_L2_NetServiceControlorN.html . When you load NETAPI32.DLL and use NetServiceControl(NULL, service_name, 3, 0, 0) (3 for SERVICE_CTRL_UNINSTALL, which is used to stop), the service stops afterwards. And it can be uninstalled and reinstalled later without DeleteFlag or reboot!
Thus, it was never a removal problem, but to stop the service properly. And NetServiceControl () does the trick. Sorry for the long post, but I thought it might help someone with similar problems. (For reference only, I am using Win7 SP1 x64.)
cxxl Jul 09 '12 at 16:15 2012-07-09 16:15
source share