Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2006, 05:06 AM
Authorized User
 
Join Date: May 2006
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to pratik28
Default Problem in UnInstalling Windows Service

I have developed a windows service in c#.NET and have used a Service controller object to control the operation of windows service such installing and uninstalling of windows service programmatically

I have used [Import("advapi32.dll")] import directive and i have invoked API calls provided ny advapi.dll such as:

"CreateService(IntPtr,SC_HANDLE,string lpSvcName,string lpDisplayName,int dwDesiredAccess,int dwServiceType,int dwStartType,int dwErrorControl,string lpPathName,string lpLoadOrderGroup,int lpdwTagId,string lpDependencies,string lpServiceStartName,string lpPassword)"

Above API Function call is working perfect. But there is problem uninstalling windows service as Installed window service persist to remain in the list of "Services" control panel of the operating system.

API Function that i have used for uninstalling windows service is:
public static extern int DeleteService(IntPtr SVHANDLE);

and Code Block i have constructed is as follows:

#CODE BEGINS HERE

public bool UnInstallService(string svcName,ref System.ServiceProcess.ServiceController SrvController)
        {
            IntPtr sc_hndl = OpenSCManager(null,null,GENERIC_WRITE);
            if(sc_hndl.ToInt32() !=0)
            {
                IntPtr svc_hndl = OpenService(sc_hndl,svcName,DELETE);

                if(svc_hndl.ToInt32() !=0)
                {
                    int i = DeleteService(svc_hndl);
                    if (i != 0)
                    {
                        CloseServiceHandle(sc_hndl);
                        sc_hndl=System.IntPtr.Zero;
                        svc_hndl=System.IntPtr.Zero;

                        SrvController=null;
                        //int temp=GC.GetGeneration(SrvController);
                        //GC.Collect(temp);
                        return true;
                    }
                    else
                    {
                        CloseServiceHandle(sc_hndl);
                        sc_hndl=System.IntPtr.Zero;
                        svc_hndl=System.IntPtr.Zero;
                        return false;
                    }
                }
                else
                    return false;
            }
            else
                return false;
        }


Hope you would send a solution for my problem. I would be thankful for your reply

imspratik
__________________
imspratik
 
Old May 14th, 2006, 10:52 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I ran into the same problem. The service actually is deleting (or trying to) but the Service Control Manager was open on my machine while I was deleting the service. After closing it and re-opening it, the service was gone. I believe this was due to the fact that the api call actually accomplishes the task by automating the SCM UI.

HTH,

Thomas

 
Old May 25th, 2006, 03:15 AM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
This is a problem with the Services management console.
I'm experiencing it with a vb.net windows service project. I use installutil.exe to install the service. The new service automatically added to the services list while the services screen is open.
But when I use the installutil.exe /u to uninstall the service, although I get a successfull unload notify on the command prompt screen, the service still is listed in the services management console. But actually, it is uninstalled.

Eralper
http://www.kodyaz.com


Eralper
http://www.kodyaz.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Service monika.vasvani ASP.NET 1.0 and 1.1 Professional 1 January 3rd, 2009 05:39 PM
Impersonate with windows service for Service A/C vinod_yadav1919 C# 0 October 18th, 2008 02:29 PM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
Windows Service bmains Pro VB.NET 2002/2003 2 January 21st, 2005 03:21 PM
Windows Service hunghung General .NET 3 January 20th, 2005 01:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.