| 303 | } |
| 304 | |
| 305 | Sid ServiceManager::GetServiceSid(const wchar_t* name) { |
| 306 | bool userService = (GetServiceStatus(name).Type & ServiceType::UserService) == ServiceType::UserService; |
| 307 | BYTE sid[SECURITY_MAX_SID_SIZE]; |
| 308 | WCHAR domain[32]; |
| 309 | DWORD domainSize = _countof(domain), sidSize = _countof(sid); |
| 310 | SID_NAME_USE use; |
| 311 | std::wstring serviceName(L"NT SERVICE\\"); |
| 312 | serviceName += name; |
| 313 | if (userService) // use base name |
| 314 | serviceName = serviceName.substr(0, serviceName.rfind(L'_')); |
| 315 | |
| 316 | if (::LookupAccountName(nullptr, serviceName.c_str(), (PSID)sid, |
| 317 | &sidSize, domain, &domainSize, &use)) |
| 318 | return Sid((PSID)sid); |
| 319 | |
| 320 | return Sid(); |
| 321 | } |