I tested in C++ on Windows 10 21H1 : I also get E_ACCESSDENIED,
but if I check the "Windows Update" service in services.msc, it becomes enabled (Manual) ...
IAutomaticUpdates2::EnableService returns Access is denied even when run as administrator
David John
1
Reputation point
I'm using the COM interface to access the Windows Update API. I get access denied when i call IAutomaticUpdates2::EnableService even though i am running as admin.
Code
fn enabled_windows_update() {
unsafe {
Com::CoInitialize(None).unwrap();
}
let gid = windows::core::GUID::from("BFE18E9C-6D87-4450-B37C-E02F0B373803");
let mut handle: windows::Win32::System::UpdateAgent::IAutomaticUpdates2 =
unsafe { Com::CoCreateInstance(&gid as *const _, None, Com::CLSCTX_ALL).unwrap() };
println!("{:?}", unsafe { handle.EnableService() });
}
2 answers
Sort by: Most helpful
-
Castorix31 86,491 Reputation points
2022-11-25T13:56:41.087+00:00 -
Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
2022-11-29T01:46:23.737+00:00 You can use Service Configuration Programs and Service Control Programs to modify or query the database of installed services and starts and controls services respectively.
There is a Complete Service Sample.