My setup
- Windows 10
- Visual Studio 2017
- Windows SDK 10.0.17763.0
I've checked a few answers similar to mine, such as:
- wrapper | OpenSCManager failed - Access is denied. (0x5)
- On Non-Admin Account OpenSCManager() function returns null
but none of those situations are as bad as mine. The other people's code all request admin permissions such as SC_MANAGER_ALL_ACCESS
but my code only asks for GENERIC_EXECUTE
, which seems perfectly normal for a regular user account:
SC_HANDLE hSC = ::OpenSCManager(NULL,
NULL, GENERIC_EXECUTE);
if (hSC == NULL) {
error("Error opening SCManager {}. Aborted.", GetLastError());
return Mam_ErrorWindowsAppleDeviceServiceInit;
}
Now this call always fails, and GetLassError()
gives: ERROR_ACCESS_DENIED
(0x5).
I tried to open Visual Studio as Admin, then the above call passes.
The above code worked a week ago. There might be a Windows10 update behind my back that I don't know of, but could this simply be a change in Windows security policy?