IAutomaticUpdates2::EnableService returns Access is denied even when run as administrator

David John 1 Reputation point
2022-11-25T11:13:26.783+00:00

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() });  
   }  
Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,736 Reputation points Microsoft External Staff
    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.

    0 comments No comments

  2. Castorix31 91,716 Reputation points
    2022-11-25T13:56:41.087+00:00

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


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.