MCPcopy Create free account
hub / github.com/Schnocker/NoEye / UninstallService

Function UninstallService

NoEye/ServiceInstaller.cpp:55–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 return result;
54 }
55 NTSTATUS NTAPI UninstallService(LPCSTR lpServiceName)
56 {
57
58 NTSTATUS result = NULL;
59 SC_HANDLE hSC = NULL, hService = NULL;
60 SERVICE_STATUS ss, sw;
61 ZeroMemory(&ss, sizeof(SERVICE_STATUS));
62 ZeroMemory(&sw, sizeof(SERVICE_STATUS));
63 hSC = OpenSCManagerA(0, 0, SC_MANAGER_ALL_ACCESS);
64 if (!hSC)
65 {
66 result = 1;
67 goto END;
68 }
69 hService = OpenServiceA(hSC, lpServiceName, SERVICE_ALL_ACCESS);
70 if (hService == NULL)
71 goto END;
72 if (!QueryServiceStatus(hService, &ss))
73 {
74 result = 2;
75 goto END;
76 }
77 if (ss.dwCurrentState == SERVICE_STOPPED)
78 goto DELETE_SERVICE;
79 if (!ControlService(hService, SERVICE_CONTROL_STOP, &sw))
80 {
81 result = 3;
82 goto END;
83 }
84 do
85 {
86 if (!QueryServiceStatus(hService, &ss))
87 {
88 result = 2;
89 goto END;
90 }
91 }
92 while (ss.dwCurrentState != SERVICE_STOPPED);
93 DELETE_SERVICE:
94 if (!DeleteService(hService))
95 {
96 result = 4;
97 goto END;
98 }
99 END:
100 if (hSC)
101 CloseServiceHandle(hSC);
102 if (hService)
103 CloseServiceHandle(hService);
104
105 return result;
106 }
107 NTSTATUS NTAPI GetServiceStatus(LPCSTR lpServiceName)
108 {
109

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected