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.


   fn enabled_windows_update() {  
       unsafe {  
       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() });  
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,511 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,904 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 83,101 Reputation points

    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) ...

  2. Xiaopo Yang - MSFT 12,226 Reputation points Microsoft Vendor

    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.

    0 comments No comments