Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How Do I delete a service from the Services Manager

Posted on 2005-04-18
4
Medium Priority
?
347 Views
Last Modified: 2013-12-03
I have been writing a  couple services with C++ and MFC and have installed them with the services manager, however I have renamed them a couple times and I have multiple entries in the service manager all of which are the same service with different names.  I can stop the services but I need to remove them completely from the service manager and am unable to do so.  How can I do this??

PT
0
Comment
Question by:ptrennum
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13806576
Delete the associated registry key(s) under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
0
 
LVL 22

Expert Comment

by:grg99
ID: 13806580
On XP, go into control panel//administrative tools//computer management//services and applications//services.

There you can do a bunch of things to disable it, *except* I don't see a *delete* option... grrrr....

You could use RegEdit (at your risk)   look in HKEY_LOCAL_MACHINE\Controlset001\Services.
I suspect that's where at least one copy of the service list exists.   It also seems to be spread out across a bunch of CLSID's, which you can probably leave dangling without much harm.  Otherwise search for the service name in Regedit and delete away.  Carefully.

0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 13806605
Or, the 'regular'  way in code:

void    RemoveService  ( LPCTSTR pszName)
{
    wchar_t     awcDomUsrName       [   LM20_DNLEN  +   LM20_UNLEN  +   1];
    wchar_t     awcWkSta            [   MAX_COMPUTERNAME_LENGTH + 2];
    DWORD       dwBufSiz            =   MAX_COMPUTERNAME_LENGTH + 1;

    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    schSCManager    =   OpenSCManager   (   NULL,                   // machine (NULL == local)
                                            NULL,                   // database (NULL == default)
                                            SC_MANAGER_ALL_ACCESS   // access required
                                        );
    if  (   schSCManager)
        {
            schService  =   OpenService (   schSCManager,
                                            pszName,
                                            SERVICE_ALL_ACCESS
                                        );

            if  (   schService)
                {
                    // try to stop the service
                    if  (   ControlService  (   schService,
                                                SERVICE_CONTROL_STOP,
                                                &g_ssStatus
                                            )
                        )
                        {
                            wprintf (   TEXT    (   "Stopping %s."),
                                        pszName
                                    );

                            Sleep   (   1000 );

                            while   (   QueryServiceStatus  (   schService,
                                                                &g_ssStatus
                                                            )
                                    )
                                    {
                                        if  (       SERVICE_STOP_PENDING    
                                                ==  g_ssStatus.dwCurrentState
                                            )
                                            {
                                                wprintf (   TEXT    (   "."));
                                                Sleep( 1000 );
                                            }
                                        else
                                                break;
                                    }

                            if  (   SERVICE_STOPPED ==  g_ssStatus.dwCurrentState)
                                    wprintf (   TEXT    (   "\n%s stopped.\n"),
                                                pszName
                                            );
                            else
                                    wprintf (   TEXT    (   "\n%s failed to stop.\n"),
                                                pszName
                                            );

                        }

                // now remove the service
                if  (   DeleteService   (   schService) )
                        wprintf (   TEXT    (   "%s removed.\n"),
                                    pszName
                                );
                else
                        wprintf (   TEXT    (   "DeleteService failed - %s\n"),
                                    GetLastErrorText    (   g_szErr,    ERROR_BUFSZ)
                                );


                CloseServiceHandle  (   schService);
            }
            else
                wprintf (   TEXT    (   "OpenService failed - %s\n"),
                            GetLastErrorText    (   g_szErr,    ERROR_BUFSZ)
                        );

            CloseServiceHandle  (   schSCManager);
        }
    else
            wprintf (   TEXT    (   "OpenSCManager failed - %s\n"),
                        GetLastErrorText    (   g_szErr,    ERROR_BUFSZ)
                    );

 
}

0
 

Author Comment

by:ptrennum
ID: 13806709
Thanks JKR,

I actually figured it out (all I had to do was re start after I used my remove service code)  It must be monday morning or something.

PT
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question