1

Hi i have prepared a windows service which setup on server by batch file (.bat file). Also i can remove it from system completely after running Uninstall.bat There is no myservice on Services.Every thing is look good.

after clicking Setup.exe , error message appears: Error 1001 The specified service already exists:

How to remove old windows service from my os completely. Or how to solve this setup problem. My uninstall.bat exe working good.

2
  • How does the batch file uninstall the service?
    – Bali C
    Commented Jul 13, 2012 at 12:25
  • Why on earth are you installing/uninstalling services with a batch file anyway? Why not just use the Custom Actions part of the installer in order to invoke the installer? msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx
    – KingCronus
    Commented Jul 13, 2012 at 12:25

4 Answers 4

1

My guess based on the description is that the service (or rather the registry key) exists indeed. You will not be able to work around this without manually intervening. What seems to happen is that you indeed remove the service, but seemingly don't stop it (or it can't be stopped).

When a service is still running when it gets removed from the SCM database, the service key will be marked for deletion internally plus there will be an additional value in the key telling the system to remove the key upon boot. The idea is that if the system gets shut down normally, the internal linked list of services to delete will be used to remove the service key and that will be done before the system restarts. If, however, the system crashes the key will be removed upon boot and before the SCM starts to bring up the services.

The internal linked list is likely what causes the trouble for you here. Because when you go through the SCM APIs that is what gets done. One way to work around this (and I have done this in the past) is to rename the key in the registry at a strategically good point in time and set it to be removed upon boot instead of using the SCM APIs.


Side note: inside an MSI you should always use the ServiceInstall/ServiceControl and Registry tables instead of using code (be it a batch file or your custom action). These actions already exist and merely need to be sequenced.

1
  • @programmerist: I gave one way to work around it that I have used myself. What more do you want? I cannot give that code as it isn't mine (it belongs to the company I worked for). Commented Jul 13, 2012 at 13:06
1

Really a question for serverfault.com, but to remove it completely, delete its registry key under HKLM\System\CurrentControlSet\Services.

Ideally, all service manipulation should be done via calls to the Service Control Manager (SCM). This can be done manually via SC.EXE. However, it sounds like your app has tried this, so delete the key and restart Windows.

2
  • i looked "HKLM\System\CurrentControlSet\Services." But i dont find my service.
    – loki
    Commented Jul 13, 2012 at 12:34
  • That's very strange. This area of the registry is the SCM's "database". A service has a display name and a short name (e.g.: Task Scheduler = schedule); I don't know how you would have specified these upon install. Have you looked for both? Have you tried a restart? Commented Jul 13, 2012 at 12:50
0

You can use MSIZAP. I it will clean all information about broken msi: http://nerdoftherings.net/wp/?p=66

1
  • I used it myself several times successfully. Commented Jul 13, 2012 at 12:52
0

Method 1: Find the directory where the msi file has been downloaded to by the Setup.exe. And execute..

msiexec /uninstall [path to msi or product code]

Method 2 (using SCM):

sc <server> delete [service name]

Try it n tell us what happens.

Not the answer you're looking for? Browse other questions tagged or ask your own question.