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
|