int UnregisterService(const char* ServiceName)
{
T_SERVICE Service;
if (!LoadServiceSetting(ServiceName,&Service))
{
printf("Service('%s') not exists or not a ServiceAny Service\n",ServiceName);
return -1;
}
SC_HANDLE hSCM = ::OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (hSCM == NULL)
return outputerr();
SC_HANDLE hService = ::OpenService(hSCM, ServiceName, SERVICE_STOP | DELETE);
int r = 0;
if (hService != NULL)
{
SERVICE_STATUS status;
::ControlService(hService, SERVICE_CONTROL_STOP, &status);
BOOL bOK = ::DeleteService(hService);
if (!bOK)
r = outputerr();
else
DeleteServiceSetting(ServiceName);
::CloseServiceHandle(hService);
}
::CloseServiceHandle(hSCM);
return r;
}
//----------------------------------------------------------------
SrvAny.dsp
# Microsoft Developer Studio Project File - Name="SrvAny" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
CFG=SrvAny - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "SrvAny.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "SrvAny.mak" CFG="SrvAny - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SrvAny - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "SrvAny - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE