source/bases/Win32Service.c
//-----------------------------------------------------------------------------
// Service_Uninstall()
//   Uninstall the service with the given name.
//-----------------------------------------------------------------------------
Service_Uninstall()
Uninstall the service with the given name.
Service_Uninstall () Uninstall the service with the given name .
static int Service_Uninstall(wchar_t *name)
{
    PyObject *fullName, *formatArgs, *nameObj;
    wchar_t *wfullName;
    SC_HANDLE managerHandle, serviceHandle;
    SERVICE_STATUS statusInfo;
    udt_ServiceInfo info;
    if (Service_SetupPython(&info) < 0)
        return -1;
    nameObj = PyUnicode_FromWideChar(name, -1);
    if (!nameObj)
        return LogPythonException("cannot create service name obj");
    formatArgs = PyTuple_Pack(1, nameObj);
    if (!formatArgs)
        return LogPythonException("cannot create service name tuple");
    Py_CLEAR(nameObj);
    fullName = PyUnicode_Format(info.nameFormat, formatArgs);
    if (!fullName)
        return LogPythonException("cannot create service name");
    managerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (!managerHandle)
        return LogWin32Error(GetLastError(), "cannot open service manager");
    wfullName = PyUnicode_AsWideCharString(fullName, NULL);
    serviceHandle = OpenServiceW(managerHandle, wfullName, SERVICE_ALL_ACCESS);
    PyMem_Free(wfullName);
    if (!serviceHandle)
        return LogWin32Error(GetLastError(), "cannot open service");
    ControlService(serviceHandle, SERVICE_CONTROL_STOP, &statusInfo);
    if (!DeleteService(serviceHandle))
        return LogWin32Error(GetLastError(), "cannot delete service");
    CloseServiceHandle(serviceHandle);
    CloseServiceHandle(managerHandle);
    return 0;
}
static int Service_Uninstall ( wchar_t * name ) { PyObject * fullName , * formatArgs , * nameObj ; wchar_t * wfullName ; SC_HANDLE managerHandle , serviceHandle ; SERVICE_STATUS statusInfo ; udt_ServiceInfo info ; if ( Service_SetupPython ( & info ) < 0 ) return -1 ; nameObj = PyUnicode_FromWideChar ( name , -1 ) ; if ( ! nameObj ) return LogPythonException ( " " ) ; formatArgs = PyTuple_Pack ( 1 , nameObj ) ; if ( ! formatArgs ) return LogPythonException ( " " ) ; Py_CLEAR ( nameObj ) ; fullName = PyUnicode_Format ( info . nameFormat , formatArgs ) ; if ( ! fullName ) return LogPythonException ( " " ) ; managerHandle = OpenSCManager ( NULL , NULL , SC_MANAGER_ALL_ACCESS ) ; if ( ! managerHandle ) return LogWin32Error ( GetLastError ( ) , " " ) ; wfullName = PyUnicode_AsWideCharString ( fullName , NULL ) ; serviceHandle = OpenServiceW ( managerHandle , wfullName , SERVICE_ALL_ACCESS ) ; PyMem_Free ( wfullName ) ; if ( ! serviceHandle ) return LogWin32Error ( GetLastError ( ) , " " ) ; ControlService ( serviceHandle , SERVICE_CONTROL_STOP , & statusInfo ) ; if ( ! DeleteService ( serviceHandle ) ) return LogWin32Error ( GetLastError ( ) , " " ) ; CloseServiceHandle ( serviceHandle ) ; CloseServiceHandle ( managerHandle ) ; return 0 ; }
Service_Uninstall()
Uninstall the service with the given name.
Service_Uninstall () Uninstall the service with the given name .
// set up Python // determine name of the service // open up service control manager // create service