How to prevent a services from being stopped by administrative users.
2023. 5. 10. 11:59 in program/windows(native)

It is almost impossible to prevent administrators from stopping services.
But there are some ways to make it difficult for them.
- Ignoring the stop notification
SetServiceStatus function (winsvc.h) - Win32 apps
Updates the service control manager's status information for the calling service.
learn.microsoft.com
If you call this function without 'SERVICE_ACCEPT_STOP' in dwControlsAccepted member in SERVICE_STAUS structure, the service ignores the stop notification.
- Chaning the access control on the service
// Get an acl of the service
ATL::CDacl dacl;
bool result = ATL::AtlGetDacl(L"serviceName", SE_SERVICE, &dacl);
// Traverse all access masks
for (UINT index = 0; index < count; ++index) {
CSid aceSid;
ACCESS_MASK mask = 0;
BYTE type = 0;
BYTE flags = 0;
GUID objectType;
GUID inheritedObjectType;
dacl.GetAclEntry(index, &aceSid, &mask, &type, &flags, &objectType, &inheritedObjectType);
}
// Change & Set acess mask
// Remove old ace
dacl.RemoveAce(speciifcIndex);
// Remove permissions(SERVICE_CHANGE_CONFIG & SERVICE_STOP)
specificMask &= ~SERVICE_CHANGE_CONFIG;
specificMask &= ~SERVICE_STOP;
// Add new ace
result = dacl.AddAllowedAce(specificSid, specificMask, specificFlags);