From fe637c0ec3a6803a95e602063bf303cc5a6a78a7 Mon Sep 17 00:00:00 2001 From: David Hall Date: Sat, 25 May 2024 21:36:44 -0600 Subject: [PATCH] WIP on WUApi parts -- NOT COMPLETE --- PInvoke/WUApi/WUApi.cs | 119 +- PInvoke/WUApi/WUApi2.cs | 52 +- PInvoke/WUApi/WUApi3.cs | 399 ++-- PInvoke/WUApi/WUApi4.cs | 34 +- PInvoke/WUApi/WUApi5.cs | 26 +- PInvoke/WUApi/WUError.cs | 1422 +++++++++++++ UnitTests/PInvoke/WUApi/WUApi.csproj | 13 +- UnitTests/PInvoke/WUApi/WUApiTests.cs | 325 ++- WindowsUpdate/Vanara.WindowsUpdate.csproj | 19 + WindowsUpdate/WindowsUpdate.cs | 3090 +++++++++++++++++++++++++++++ 10 files changed, 5138 insertions(+), 361 deletions(-) create mode 100644 PInvoke/WUApi/WUError.cs create mode 100644 WindowsUpdate/Vanara.WindowsUpdate.csproj create mode 100644 WindowsUpdate/WindowsUpdate.cs diff --git a/PInvoke/WUApi/WUApi.cs b/PInvoke/WUApi/WUApi.cs index 2e97e4d9..4979bbc0 100644 --- a/PInvoke/WUApi/WUApi.cs +++ b/PInvoke/WUApi/WUApi.cs @@ -1,7 +1,6 @@ global using System.Collections; global using System.Reflection; global using System.Runtime.CompilerServices; -using System.Net; namespace Vanara.PInvoke; @@ -899,7 +898,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iautomaticupdates [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IAutomaticUpdates")] - [ComImport, Guid("673425BF-C082-4C7C-BDFD-569464B8E0CE"), CoClass(typeof(AutomaticUpdates))] + [ComImport, Guid("673425BF-C082-4C7C-BDFD-569464B8E0CE"), CoClass(typeof(AutomaticUpdatesClass))] public interface IAutomaticUpdates { /// @@ -992,7 +991,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iautomaticupdates2 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IAutomaticUpdates2")] - [ComImport, Guid("4A2F5C31-CFD9-410E-B7FB-29A653973A0F"), CoClass(typeof(AutomaticUpdates))] + [ComImport, Guid("4A2F5C31-CFD9-410E-B7FB-29A653973A0F"), CoClass(typeof(AutomaticUpdatesClass))] public interface IAutomaticUpdates2 : IAutomaticUpdates { /// @@ -1104,7 +1103,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-uamg/edb37e74-f222-4983-b1fc-4d9694386619 [DispId(1610743809)] - object LastSearchSuccessDate + object? LastSearchSuccessDate { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] [return: MarshalAs(UnmanagedType.Struct)] @@ -1121,7 +1120,7 @@ public static partial class WUApi /// this property. /// [DispId(1610743810)] - object LastInstallationSuccessDate + object? LastInstallationSuccessDate { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] [return: MarshalAs(UnmanagedType.Struct)] @@ -1663,7 +1662,7 @@ public static partial class WUApi // CheckPermission( [in] AutomaticUpdatesUserType userType, [in] AutomaticUpdatesPermissionType permissionType, VARIANT_BOOL // *userHasPermission ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - bool CheckPermission([In][ComAliasName("WUApiLib.AutomaticUpdatesUserType")] AutomaticUpdatesUserType userType, [In][ComAliasName("WUApiLib.AutomaticUpdatesPermissionType")] AutomaticUpdatesPermissionType permissionType); + bool CheckPermission([In, ComAliasName("WUApiLib.AutomaticUpdatesUserType")] AutomaticUpdatesUserType userType, [In, ComAliasName("WUApiLib.AutomaticUpdatesPermissionType")] AutomaticUpdatesPermissionType permissionType); } /// Contains the settings that are available in Automatic Updates. @@ -1946,7 +1945,7 @@ public static partial class WUApi // CheckPermission( [in] AutomaticUpdatesUserType userType, [in] AutomaticUpdatesPermissionType permissionType, VARIANT_BOOL // *userHasPermission ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - new bool CheckPermission([In][ComAliasName("WUApiLib.AutomaticUpdatesUserType")] AutomaticUpdatesUserType userType, [In][ComAliasName("WUApiLib.AutomaticUpdatesPermissionType")] AutomaticUpdatesPermissionType permissionType); + new bool CheckPermission([In, ComAliasName("WUApiLib.AutomaticUpdatesUserType")] AutomaticUpdatesUserType userType, [In, ComAliasName("WUApiLib.AutomaticUpdatesPermissionType")] AutomaticUpdatesPermissionType permissionType); /// /// @@ -2041,7 +2040,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_categoryid HRESULT get_CategoryID( BSTR *retval ); [DispId(1610743809)] - string CategoryID + string? CategoryID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] [return: MarshalAs(UnmanagedType.BStr)] @@ -2055,7 +2054,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_children HRESULT get_Children( // ICategoryCollection **retval ); [DispId(1610743810)] - ICategoryCollection Children + ICategoryCollection? Children { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] [return: MarshalAs(UnmanagedType.Interface)] @@ -2095,7 +2094,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_description HRESULT get_Description( BSTR *retval ); [DispId(1610743811)] - string Description + string? Description { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] [return: MarshalAs(UnmanagedType.BStr)] @@ -2136,7 +2135,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_image HRESULT get_Image( IImageInformation // **retval ); [DispId(1610743812)] - IImageInformation Image + IImageInformation? Image { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] [return: MarshalAs(UnmanagedType.Interface)] @@ -2161,7 +2160,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_parent HRESULT get_Parent( ICategory **retval ); [DispId(1610743814)] - ICategory Parent + ICategory? Parent { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] [return: MarshalAs(UnmanagedType.Interface)] @@ -2190,7 +2189,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-icategory-get_updates HRESULT get_Updates( IUpdateCollection // **retval ); [DispId(1610743816)] - IUpdateCollection Updates + IUpdateCollection? Updates { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] [return: MarshalAs(UnmanagedType.Interface)] @@ -2259,7 +2258,7 @@ public static partial class WUApi // HRESULT Invoke( [in] IDownloadJob *downloadJob, [in] IDownloadCompletedCallbackArgs *callbackArgs ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [PreserveSig] - HRESULT Invoke([In][MarshalAs(UnmanagedType.Interface)] IDownloadJob downloadJob, [In][MarshalAs(UnmanagedType.Interface)] IDownloadCompletedCallbackArgs callbackArgs); + HRESULT Invoke([In, MarshalAs(UnmanagedType.Interface)] IDownloadJob downloadJob, [In, MarshalAs(UnmanagedType.Interface)] IDownloadCompletedCallbackArgs callbackArgs); } /// @@ -2504,7 +2503,7 @@ public static partial class WUApi // HRESULT Invoke( [in] IDownloadJob *downloadJob, [in] IDownloadProgressChangedCallbackArgs *callbackArgs ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [PreserveSig] - HRESULT Invoke([In][MarshalAs(UnmanagedType.Interface)] IDownloadJob downloadJob, [In][MarshalAs(UnmanagedType.Interface)] IDownloadProgressChangedCallbackArgs callbackArgs); + HRESULT Invoke([In, MarshalAs(UnmanagedType.Interface)] IDownloadJob downloadJob, [In, MarshalAs(UnmanagedType.Interface)] IDownloadProgressChangedCallbackArgs callbackArgs); } /// Contains information about the change in the progress of an asynchronous download operation. @@ -2531,7 +2530,7 @@ public static partial class WUApi /// The IDownloadResult interface represents the result of a download operation. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-idownloadresult [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IDownloadResult")] - [ComImport, Guid("DAA4FDD0-4727-4DBE-A1E7-745DCA317144")] + [ComImport, Guid("daa4fdd0-4727-4dbe-a1e7-745dca317144")] public interface IDownloadResult { /// @@ -2539,10 +2538,10 @@ public static partial class WUApi /// This property is read-only. /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-idownloadresult-get_hresult HRESULT get_HResult( LONG *retval ); - [DispId(1610743809)] - HRESULT HResult + [DispId(0x60020001)] + int HResult { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -2552,10 +2551,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-idownloadresult-get_resultcode HRESULT get_ResultCode( // OperationResultCode *retval ); - [ComAliasName("WUApiLib.OperationResultCode"), DispId(1610743810)] + [ComAliasName("WUApiLib.OperationResultCode"), DispId(0x60020002)] OperationResultCode ResultCode { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [return: ComAliasName("WUApiLib.OperationResultCode")] get; } @@ -2565,7 +2564,7 @@ public static partial class WUApi /// An IUpdateDownloadResult interface that contains the results for the specified update. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-idownloadresult-getupdateresult HRESULT GetUpdateResult( [in] // LONG updateIndex, [out] IUpdateDownloadResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: MarshalAs(UnmanagedType.Interface)] IUpdateDownloadResult GetUpdateResult([In] int updateIndex); } @@ -2630,7 +2629,7 @@ public static partial class WUApi /// Records the result for an update. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iinstallationagent [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IInstallationAgent")] - [ComImport, Guid("925CBC18-A2EA-4648-BF1C-EC8BADCFE20A"), CoClass(typeof(InstallationAgent))] + [ComImport, Guid("925CBC18-A2EA-4648-BF1C-EC8BADCFE20A"), CoClass(typeof(InstallationAgentClass))] public interface IInstallationAgent { /// Records the result for an update. The result is specified by an IStringCollection object. @@ -2642,7 +2641,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationagent-recordinstallationresult HRESULT // RecordInstallationResult( [in] BSTR installationResultCookie, [in] LONG hresult, [in] IStringCollection *extendedReportingData ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] - void RecordInstallationResult([In][MarshalAs(UnmanagedType.BStr)] string installationResultCookie, [In] HRESULT hresult, [In][MarshalAs(UnmanagedType.Interface)] IStringCollection extendedReportingData); + void RecordInstallationResult([In, MarshalAs(UnmanagedType.BStr)] string installationResultCookie, [In] HRESULT hresult, [In, MarshalAs(UnmanagedType.Interface)] IStringCollection extendedReportingData); } /// Represents the installation and uninstallation options of an update. @@ -2730,7 +2729,7 @@ public static partial class WUApi // IInstallationJob *installationJob, [in] IInstallationCompletedCallbackArgs *callbackArgs ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [PreserveSig] - HRESULT Invoke([In][MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, [In][MarshalAs(UnmanagedType.Interface)] IInstallationCompletedCallbackArgs? callbackArgs); + HRESULT Invoke([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, [In, MarshalAs(UnmanagedType.Interface)] IInstallationCompletedCallbackArgs? callbackArgs); } /// @@ -2766,10 +2765,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-get_asyncstate HRESULT get_AsyncState( VARIANT // *retval ); - [DispId(1610743809)] - object AsyncState + [DispId(0x60020001)] + object? AsyncState { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.Struct)] get; } @@ -2783,10 +2782,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-get_iscompleted HRESULT get_IsCompleted( // VARIANT_BOOL *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] bool IsCompleted { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; } @@ -2796,10 +2795,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-get_updates HRESULT get_Updates( // IUpdateCollection **retval ); - [DispId(1610743811)] + [DispId(0x60020003)] IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: MarshalAs(UnmanagedType.Interface)] get; } @@ -2810,7 +2809,7 @@ public static partial class WUApi /// perform asynchronous WUA operations, see Guidelines for Asynchronous WUA Operations. /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-cleanup HRESULT CleanUp(); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] void CleanUp(); /// Returns an IInstallationProgress interface that describes the current progress of an installation or uninstallation. @@ -2821,13 +2820,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-getprogress HRESULT GetProgress( [out] // IInstallationProgress **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationProgress GetProgress(); /// Makes a request to cancel the installation or uninstallation. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-requestabort HRESULT RequestAbort(); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] void RequestAbort(); } @@ -2846,10 +2845,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationprogress-get_currentupdateindex HRESULT // get_CurrentUpdateIndex( LONG *retval ); - [DispId(1610743809)] + [DispId(0x60020001)] int CurrentUpdateIndex { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -2859,10 +2858,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationprogress-get_currentupdatepercentcomplete HRESULT // get_CurrentUpdatePercentComplete( LONG *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] int CurrentUpdatePercentComplete { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; } @@ -2872,10 +2871,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationprogress-get_percentcomplete HRESULT // get_PercentComplete( LONG *retval ); - [DispId(1610743811)] + [DispId(0x60020003)] int PercentComplete { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] get; } @@ -2888,7 +2887,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationprogress-getupdateresult HRESULT GetUpdateResult( // [in] LONG updateIndex, [out] IUpdateInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.Interface)] IUpdateInstallationResult GetUpdateResult([In] int updateIndex); } @@ -2913,7 +2912,7 @@ public static partial class WUApi // [in] IInstallationJob *installationJob, [in] IInstallationProgressChangedCallbackArgs *callbackArgs ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [PreserveSig] - HRESULT Invoke([In][MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, [In][MarshalAs(UnmanagedType.Interface)] IInstallationProgressChangedCallbackArgs callbackArgs); + HRESULT Invoke([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, [In, MarshalAs(UnmanagedType.Interface)] IInstallationProgressChangedCallbackArgs callbackArgs); } /// @@ -2932,10 +2931,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationprogresschangedcallbackargs-get_progress HRESULT // get_Progress( IInstallationProgress **retval ); - [DispId(1610743809)] + [DispId(0x60020001)] IInstallationProgress Progress { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.Interface)] get; } @@ -2953,10 +2952,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationresult-get_hresult HRESULT get_HResult( LONG // *retval ); - [DispId(1610743809)] - HRESULT HResult + [DispId(0x60020001)] + int HResult { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -2968,10 +2967,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationresult-get_rebootrequired HRESULT // get_RebootRequired( VARIANT_BOOL *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] bool RebootRequired { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; } @@ -2981,10 +2980,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationresult-get_resultcode HRESULT get_ResultCode( // OperationResultCode *retval ); - [DispId(1610743811), ComAliasName("WUApiLib.OperationResultCode")] + [DispId(0x60020003), ComAliasName("WUApiLib.OperationResultCode")] OperationResultCode ResultCode { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.OperationResultCode")] get; } @@ -2994,7 +2993,7 @@ public static partial class WUApi /// An interface that contains results for a specified update. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationresult-getupdateresult HRESULT GetUpdateResult( // [in] LONG updateIndex, [out] IUpdateInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.Interface)] IUpdateInstallationResult GetUpdateResult([In] int updateIndex); } @@ -3024,7 +3023,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateexception-get_hresult HRESULT get_HResult( LONG *retval ); [DispId(1610743809)] - new HRESULT HResult + new int HResult { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] get; @@ -3080,7 +3079,7 @@ public static partial class WUApi // *searchJob, [in] ISearchCompletedCallbackArgs *callbackArgs ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [PreserveSig] - HRESULT Invoke([In][MarshalAs(UnmanagedType.Interface)] ISearchJob searchJob, [In][MarshalAs(UnmanagedType.Interface)] ISearchCompletedCallbackArgs callbackArgs); + HRESULT Invoke([In] ISearchJob searchJob, [In] ISearchCompletedCallbackArgs callbackArgs); } /// @@ -3107,7 +3106,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-isearchjob-get_asyncstate HRESULT get_AsyncState( VARIANT // *retval ); [DispId(1610743809)] - object AsyncState + object? AsyncState { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] [return: MarshalAs(UnmanagedType.Struct)] @@ -3212,7 +3211,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-istringcollection [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IStringCollection")] - [ComImport, Guid("EFF90582-2DDC-480F-A06D-60F3FBC362C3"), CoClass(typeof(StringCollection))] + [ComImport, Guid("EFF90582-2DDC-480F-A06D-60F3FBC362C3"), CoClass(typeof(StringCollectionClass))] public interface IStringCollection : IEnumerable { /// @@ -3274,7 +3273,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-istringcollection-add HRESULT Add( [in] BSTR value, [out] LONG // *retval ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] - int Add([In][MarshalAs(UnmanagedType.BStr)] string value); + int Add([In, MarshalAs(UnmanagedType.BStr)] string value); /// Removes all the elements from the collection. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-istringcollection-clear HRESULT Clear(); @@ -3295,7 +3294,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-istringcollection-insert HRESULT Insert( [in] LONG index, [in] // BSTR value ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] - void Insert([In] int index, [In][MarshalAs(UnmanagedType.BStr)] string value); + void Insert([In] int index, [In, MarshalAs(UnmanagedType.BStr)] string value); /// Removes the item at the specified index from the collection. /// The index of the string to be removed. @@ -3311,7 +3310,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-isysteminformation [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.ISystemInformation")] - [ComImport, Guid("ADE87BF7-7B56-4275-8FAB-B9B0E591844B"), CoClass(typeof(SystemInformation))] + [ComImport, Guid("ADE87BF7-7B56-4275-8FAB-B9B0E591844B"), CoClass(typeof(SystemInformationClass))] public interface ISystemInformation { /// diff --git a/PInvoke/WUApi/WUApi2.cs b/PInvoke/WUApi/WUApi2.cs index 47e2cf47..51a7b03a 100644 --- a/PInvoke/WUApi/WUApi2.cs +++ b/PInvoke/WUApi/WUApi2.cs @@ -262,7 +262,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-get_handlerid HRESULT get_HandlerID( BSTR *retval ); [DispId(1610743819)] - string HandlerID + string? HandlerID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] [return: MarshalAs(UnmanagedType.BStr)] @@ -868,7 +868,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -1154,7 +1154,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-get_handlerid HRESULT get_HandlerID( BSTR *retval ); [DispId(1610743819)] - new string HandlerID + new string? HandlerID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] [return: MarshalAs(UnmanagedType.BStr)] @@ -1760,7 +1760,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -1874,7 +1874,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate2-copytocache HRESULT CopyToCache( [in] // IStringCollection *pFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - void CopyToCache([In][MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); + void CopyToCache([In, MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); } /// Contains the properties and methods that are available to an update. @@ -2132,7 +2132,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-get_handlerid HRESULT get_HandlerID( BSTR *retval ); [DispId(1610743819)] - new string HandlerID + new string? HandlerID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] [return: MarshalAs(UnmanagedType.BStr)] @@ -2738,7 +2738,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -2852,7 +2852,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate2-copytocache HRESULT CopyToCache( [in] // IStringCollection *pFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - new void CopyToCache([In][MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); + new void CopyToCache([In, MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); /// /// Gets a Boolean value that indicates whether an update can be discovered only by browsing through the available updates. @@ -3123,7 +3123,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-get_handlerid HRESULT get_HandlerID( BSTR *retval ); [DispId(1610743819)] - new string HandlerID + new string? HandlerID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] [return: MarshalAs(UnmanagedType.BStr)] @@ -3729,7 +3729,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -3843,7 +3843,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate2-copytocache HRESULT CopyToCache( [in] // IStringCollection *pFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - new void CopyToCache([In][MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); + new void CopyToCache([In, MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); /// /// Gets a Boolean value that indicates whether an update can be discovered only by browsing through the available updates. @@ -4135,7 +4135,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-get_handlerid HRESULT get_HandlerID( BSTR *retval ); [DispId(1610743819)] - new string HandlerID + new string? HandlerID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] [return: MarshalAs(UnmanagedType.BStr)] @@ -4741,7 +4741,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -4855,7 +4855,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate2-copytocache HRESULT CopyToCache( [in] // IStringCollection *pFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809346)] - new void CopyToCache([In][MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); + new void CopyToCache([In, MarshalAs(UnmanagedType.Interface)] IStringCollection pFiles); /// /// Gets a Boolean value that indicates whether an update can be discovered only by browsing through the available updates. @@ -4932,7 +4932,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatecollection [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateCollection")] - [ComImport, Guid("07F7438C-7709-4CA5-B518-91279288134E"), CoClass(typeof(UpdateCollection))] + [ComImport, Guid("07f7438c-7709-4ca5-b518-91279288134e"), CoClass(typeof(UpdateCollectionClass))/*, TypeLibType(TypeLibTypeFlags.FDispatchable | TypeLibTypeFlags.FHidden | TypeLibTypeFlags.FDual | TypeLibTypeFlags.FNonExtensible)*/] public interface IUpdateCollection : IEnumerable { /// @@ -4968,10 +4968,10 @@ public static partial class WUApi /// This property is read-only. /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-get_count HRESULT get_Count( LONG *retval ); - [DispId(1610743809)] + [DispId(0x60020001)] int Count { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -4981,10 +4981,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-get_readonly HRESULT get_ReadOnly( // VARIANT_BOOL *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] bool ReadOnly { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; } @@ -4993,19 +4993,19 @@ public static partial class WUApi /// The index of the added interface in the collection. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-add HRESULT Add( [in] IUpdate *value, [out] // LONG *retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] - int Add([In][MarshalAs(UnmanagedType.Interface)] IUpdate value); + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] + int Add([In, MarshalAs(UnmanagedType.Interface)] IUpdate value); /// Removes all the elements from the collection. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-clear HRESULT Clear(); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] void Clear(); /// Creates a shallow read/write copy of the collection. /// A shallow read/write copy of the collection. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-copy HRESULT Copy( [out] IUpdateCollection // **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] IUpdateCollection Copy(); @@ -5014,13 +5014,13 @@ public static partial class WUApi /// The IUpdate interface that will be inserted. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-insert HRESULT Insert( [in] LONG index, [in] // IUpdate *value ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] - void Insert([In] int index, [In][MarshalAs(UnmanagedType.Interface)] IUpdate value); + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] + void Insert([In] int index, [In, MarshalAs(UnmanagedType.Interface)] IUpdate value); /// Removes the item at the specified index from the collection. /// The index of the interface to be removed. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatecollection-removeat HRESULT RemoveAt( [in] LONG index ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] void RemoveAt([In] int index); } } \ No newline at end of file diff --git a/PInvoke/WUApi/WUApi3.cs b/PInvoke/WUApi/WUApi3.cs index 6a797170..fc0970b2 100644 --- a/PInvoke/WUApi/WUApi3.cs +++ b/PInvoke/WUApi/WUApi3.cs @@ -116,7 +116,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatedownloader [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateDownloader")] - [ComImport, Guid("68F1C6F9-7ECC-4666-A464-247FE12496C3"), CoClass(typeof(UpdateDownloader))] + [ComImport, Guid("68f1c6f9-7ecc-4666-a464-247fe12496c3"), CoClass(typeof(UpdateDownloaderClass))] public interface IUpdateDownloader { /// @@ -126,13 +126,13 @@ public static partial class WUApi /// Returns the value Unknown if the client application has not set the property. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-get_clientapplicationid HRESULT // get_ClientApplicationID( BSTR *retval ); - [DispId(1610743809)] - string ClientApplicationID + [DispId(0x60020001)] + string? ClientApplicationID { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.BStr)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [param: In, MarshalAs(UnmanagedType.BStr)] set; } @@ -147,12 +147,12 @@ public static partial class WUApi /// This method returns WU_E_INVALID_OPERATION if the object that is implementing the interface is locked down. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-get_isforced HRESULT get_IsForced( // VARIANT_BOOL *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] bool IsForced { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [param: In] set; } @@ -163,13 +163,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-get_priority HRESULT get_Priority( // DownloadPriority *retval ); - [DispId(1610743811), ComAliasName("WUApiLib.DownloadPriority")] + [DispId(0x60020003), ComAliasName("WUApiLib.DownloadPriority")] DownloadPriority Priority { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.DownloadPriority")] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [param: In, ComAliasName("WUApiLib.DownloadPriority")] set; } @@ -180,13 +180,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-put_updates HRESULT put_Updates( // IUpdateCollection *value ); - [DispId(1610743812)] + [DispId(0x60020004)] IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.Interface)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [param: In, MarshalAs(UnmanagedType.Interface)] set; } @@ -240,9 +240,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-begindownload HRESULT BeginDownload( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IDownloadJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] - IDownloadJob BeginDownload([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + IDownloadJob BeginDownload([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Starts a synchronous download of the content files that are associated with the updates. /// An IDownloadResult interface that contains result codes for the download. @@ -256,7 +257,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-download HRESULT Download( [out] // IDownloadResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] [return: MarshalAs(UnmanagedType.Interface)] IDownloadResult Download(); @@ -272,7 +273,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloader-enddownload HRESULT EndDownload( [in] // IDownloadJob *value, [out] IDownloadResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] [return: MarshalAs(UnmanagedType.Interface)] IDownloadResult EndDownload([In, MarshalAs(UnmanagedType.Interface)] IDownloadJob value); } @@ -280,7 +281,7 @@ public static partial class WUApi /// Contains the properties that indicate the status of a download operation for an update. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatedownloadresult [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateDownloadResult")] - [ComImport, Guid("BF99AF76-B575-42AD-8AA4-33CBB5477AF1")] + [ComImport, Guid("bf99af76-b575-42ad-8aa4-33cbb5477af1")] public interface IUpdateDownloadResult { /// @@ -289,10 +290,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloadresult-get_hresult HRESULT get_HResult( LONG // *retval ); - [DispId(1610743809)] - HRESULT HResult + [DispId(0x60020001)] + int HResult { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -302,10 +303,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatedownloadresult-get_resultcode HRESULT get_ResultCode( // OperationResultCode *retval ); - [ComAliasName("WUApiLib.OperationResultCode"), DispId(1610743810)] + [ComAliasName("WUApiLib.OperationResultCode"), DispId(0x60020002)] OperationResultCode ResultCode { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [return: ComAliasName("WUApiLib.OperationResultCode")] get; } @@ -346,7 +347,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateexception-get_hresult HRESULT get_HResult( LONG *retval ); [DispId(1610743809)] - HRESULT HResult + int HResult { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] get; @@ -455,7 +456,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatehistoryentry-get_hresult HRESULT get_HResult( LONG // *retval ); [DispId(1610743811)] - HRESULT HResult + int HResult { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] get; @@ -749,7 +750,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatehistoryentry-get_hresult HRESULT get_HResult( LONG // *retval ); [DispId(1610743811)] - new HRESULT HResult + new int HResult { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] get; @@ -1076,11 +1077,8 @@ public static partial class WUApi [ComImport, Guid("46297823-9940-4C09-AED9-CD3EA6D05968")] public interface IUpdateIdentity { - /// - /// Gets the revision-independent identifier of an update. - /// This property is read-only. - /// - // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateidentity-get_updateid HRESULT get_UpdateID( BSTR *retval ); + /// Gest the revision number of the update. + // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-uamg/e9c2b583-44a9-4300-9650-871c15c07a65 [DispId(1610743810)] int RevisionNumber { @@ -1088,10 +1086,7 @@ public static partial class WUApi get; } - /// - /// Gets the revision-independent identifier of an update. - /// This property is read-only. - /// + /// Gets the revision-independent identifier of an update. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateidentity-get_updateid HRESULT get_UpdateID( BSTR *retval ); [DispId(1610743811)] string UpdateID @@ -1114,10 +1109,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstallationresult-get_hresult HRESULT get_HResult( LONG // *retval ); - [DispId(1610743809)] - HRESULT HResult + [DispId(0x60020001)] + int HResult { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] get; } @@ -1129,10 +1124,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstallationresult-get_rebootrequired HRESULT // get_RebootRequired( VARIANT_BOOL *retval ); - [DispId(1610743810)] + [DispId(0x60020002)] bool RebootRequired { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; } @@ -1142,10 +1137,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstallationresult-get_resultcode HRESULT // get_ResultCode( OperationResultCode *retval ); - [ComAliasName("WUApiLib.OperationResultCode"), DispId(1610743811)] + [ComAliasName("WUApiLib.OperationResultCode"), DispId(0x60020003)] OperationResultCode ResultCode { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.OperationResultCode")] get; } @@ -1158,7 +1153,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateinstaller [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateInstaller")] - [ComImport, ComConversionLoss, Guid("7B929C68-CCDC-4226-96B1-8724600B54C2")] + [ComImport, ComConversionLoss, Guid("7b929c68-ccdc-4226-96b1-8724600b54c2"), CoClass(typeof(UpdateInstallerClass))] public interface IUpdateInstaller { /// @@ -1168,13 +1163,13 @@ public static partial class WUApi /// Returns the Unknown value if the client application has not set the property. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_clientapplicationid HRESULT // put_ClientApplicationID( BSTR value ); - [DispId(1610743809)] - string ClientApplicationID + [DispId(0x60020001)] + string? ClientApplicationID { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.BStr)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [param: In, MarshalAs(UnmanagedType.BStr)] set; } @@ -1197,12 +1192,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_isforced HRESULT put_IsForced( // VARIANT_BOOL value ); - [DispId(1610743810)] + [DispId(0x60020002)] bool IsForced { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [param: In] set; } @@ -1216,13 +1211,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parenthwnd HRESULT get_ParentHwnd( HWND // *retval ); - [ComAliasName("WUApiLib.wireHWND"), DispId(1610743811)] + [ComAliasName("WUApiLib.wireHWND"), DispId(0x60020003)] HWND ParentHwnd { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.wireHWND")] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [param: In, ComAliasName("WUApiLib.wireHWND")] set; } @@ -1236,13 +1231,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parentwindow HRESULT get_ParentWindow( // IUnknown **retval ); - [DispId(1610743812)] - object parentWindow + [DispId(0x60020004)] + object? parentWindow { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.IUnknown)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [param: In, MarshalAs(UnmanagedType.IUnknown)] set; } @@ -1253,13 +1248,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_updates HRESULT get_Updates( // IUpdateCollection **retval ); - [DispId(1610743813)] + [DispId(0x60020005)] IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [param: In, MarshalAs(UnmanagedType.Interface)] set; } @@ -1292,10 +1287,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-begininstall HRESULT BeginInstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationJob BeginInstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Starts an asynchronous uninstallation of the updates. /// @@ -1325,10 +1320,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-beginuninstall HRESULT BeginUninstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationJob BeginUninstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Completes an asynchronous installation of the updates. /// The IInstallationJob interface that is returned by the BeginInstall method. @@ -1339,7 +1334,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-endinstall HRESULT EndInstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020008)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationResult EndInstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1352,7 +1347,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-enduninstall HRESULT EndUninstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743817)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020009)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationResult EndUninstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1366,7 +1361,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-install HRESULT Install( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743818)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000a)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationResult Install(); @@ -1385,7 +1380,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-runwizard HRESULT RunWizard( [in, optional] // BSTR dialogTitle, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000b)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationResult RunWizard([In, MarshalAs(UnmanagedType.BStr)] string dialogTitle = ""); @@ -1404,10 +1399,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_isbusy HRESULT get_IsBusy( VARIANT_BOOL // *retval ); - [DispId(1610743820)] + [DispId(0x6002000c)] bool IsBusy { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743820)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000c)] get; } @@ -1422,7 +1417,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-uninstall HRESULT Uninstall( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743821)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000d)] [return: MarshalAs(UnmanagedType.Interface)] IInstallationResult Uninstall(); @@ -1432,12 +1427,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_allowsourceprompts HRESULT // put_AllowSourcePrompts( VARIANT_BOOL value ); - [DispId(1610743822)] + [DispId(0x6002000e)] bool AllowSourcePrompts { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] [param: In] set; } @@ -1448,10 +1443,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_rebootrequiredbeforeinstallation HRESULT // get_RebootRequiredBeforeInstallation( VARIANT_BOOL *retval ); - [DispId(1610743823)] + [DispId(0x6002000f)] bool RebootRequiredBeforeInstallation { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743823)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000f)] get; } } @@ -1463,7 +1458,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateinstaller2 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateInstaller2")] - [ComImport, Guid("3442D4FE-224D-4CEE-98CF-30E0C4D229E6"), CoClass(typeof(UpdateInstaller))] + [ComImport, Guid("3442d4fe-224d-4cee-98cf-30e0c4d229e6"), CoClass(typeof(UpdateInstallerClass))] public interface IUpdateInstaller2 : IUpdateInstaller { /// @@ -1473,13 +1468,13 @@ public static partial class WUApi /// Returns the Unknown value if the client application has not set the property. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_clientapplicationid HRESULT // put_ClientApplicationID( BSTR value ); - [DispId(1610743809)] - new string ClientApplicationID + [DispId(0x60020001)] + new string? ClientApplicationID { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.BStr)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [param: In, MarshalAs(UnmanagedType.BStr)] set; } @@ -1502,12 +1497,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_isforced HRESULT put_IsForced( // VARIANT_BOOL value ); - [DispId(1610743810)] + [DispId(0x60020002)] new bool IsForced { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [param: In] set; } @@ -1521,13 +1516,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parenthwnd HRESULT get_ParentHwnd( HWND // *retval ); - [ComAliasName("WUApiLib.wireHWND"), DispId(1610743811)] + [ComAliasName("WUApiLib.wireHWND"), DispId(0x60020003)] new HWND ParentHwnd { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.wireHWND")] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [param: In, ComAliasName("WUApiLib.wireHWND")] set; } @@ -1541,13 +1536,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parentwindow HRESULT get_ParentWindow( // IUnknown **retval ); - [DispId(1610743812)] - new object parentWindow + [DispId(0x60020004)] + new object? parentWindow { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.IUnknown)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [param: In, MarshalAs(UnmanagedType.IUnknown)] set; } @@ -1558,13 +1553,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_updates HRESULT get_Updates( // IUpdateCollection **retval ); - [DispId(1610743813)] + [DispId(0x60020005)] new IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [param: In, MarshalAs(UnmanagedType.Interface)] set; } @@ -1597,10 +1592,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-begininstall HRESULT BeginInstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginInstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Starts an asynchronous uninstallation of the updates. /// @@ -1630,10 +1625,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-beginuninstall HRESULT BeginUninstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginUninstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Completes an asynchronous installation of the updates. /// The IInstallationJob interface that is returned by the BeginInstall method. @@ -1644,7 +1639,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-endinstall HRESULT EndInstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020008)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndInstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1657,7 +1652,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-enduninstall HRESULT EndUninstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743817)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020009)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndUninstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1671,7 +1666,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-install HRESULT Install( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743818)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000a)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Install(); @@ -1690,7 +1685,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-runwizard HRESULT RunWizard( [in, optional] // BSTR dialogTitle, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000b)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult RunWizard([In, MarshalAs(UnmanagedType.BStr)] string dialogTitle = ""); @@ -1709,10 +1704,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_isbusy HRESULT get_IsBusy( VARIANT_BOOL // *retval ); - [DispId(1610743820)] + [DispId(0x6002000c)] new bool IsBusy { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743820)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000c)] get; } @@ -1727,7 +1722,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-uninstall HRESULT Uninstall( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743821)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000d)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Uninstall(); @@ -1737,12 +1732,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_allowsourceprompts HRESULT // put_AllowSourcePrompts( VARIANT_BOOL value ); - [DispId(1610743822)] + [DispId(0x6002000e)] new bool AllowSourcePrompts { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] [param: In] set; } @@ -1753,10 +1748,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_rebootrequiredbeforeinstallation HRESULT // get_RebootRequiredBeforeInstallation( VARIANT_BOOL *retval ); - [DispId(1610743823)] + [DispId(0x6002000f)] new bool RebootRequiredBeforeInstallation { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743823)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000f)] get; } @@ -1770,12 +1765,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller2-put_forcequiet HRESULT put_ForceQuiet( // VARIANT_BOOL value ); - [DispId(1610809345)] + [DispId(0x60030001)] bool ForceQuiet { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] [param: In] set; } @@ -1787,7 +1782,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateinstaller3 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateInstaller3")] - [ComImport, Guid("16D11C35-099A-48D0-8338-5FAE64047F8E")] + [ComImport, Guid("16d11c35-099a-48d0-8338-5fae64047f8e")] public interface IUpdateInstaller3 : IUpdateInstaller2 { /// @@ -1797,13 +1792,13 @@ public static partial class WUApi /// Returns the Unknown value if the client application has not set the property. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_clientapplicationid HRESULT // put_ClientApplicationID( BSTR value ); - [DispId(1610743809)] - new string ClientApplicationID + [DispId(0x60020001)] + new string? ClientApplicationID { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.BStr)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [param: In, MarshalAs(UnmanagedType.BStr)] set; } @@ -1826,12 +1821,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_isforced HRESULT put_IsForced( // VARIANT_BOOL value ); - [DispId(1610743810)] + [DispId(0x60020002)] new bool IsForced { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [param: In] set; } @@ -1845,13 +1840,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parenthwnd HRESULT get_ParentHwnd( HWND // *retval ); - [ComAliasName("WUApiLib.wireHWND"), DispId(1610743811)] + [ComAliasName("WUApiLib.wireHWND"), DispId(0x60020003)] new HWND ParentHwnd { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.wireHWND")] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [param: In, ComAliasName("WUApiLib.wireHWND")] set; } @@ -1865,13 +1860,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parentwindow HRESULT get_ParentWindow( // IUnknown **retval ); - [DispId(1610743812)] - new object parentWindow + [DispId(0x60020004)] + new object? parentWindow { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.IUnknown)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [param: In, MarshalAs(UnmanagedType.IUnknown)] set; } @@ -1882,13 +1877,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_updates HRESULT get_Updates( // IUpdateCollection **retval ); - [DispId(1610743813)] + [DispId(0x60020005)] new IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [param: In, MarshalAs(UnmanagedType.Interface)] set; } @@ -1921,10 +1916,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-begininstall HRESULT BeginInstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginInstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Starts an asynchronous uninstallation of the updates. /// @@ -1954,10 +1949,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-beginuninstall HRESULT BeginUninstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginUninstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Completes an asynchronous installation of the updates. /// The IInstallationJob interface that is returned by the BeginInstall method. @@ -1968,7 +1963,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-endinstall HRESULT EndInstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020008)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndInstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1981,7 +1976,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-enduninstall HRESULT EndUninstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743817)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020009)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndUninstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -1995,7 +1990,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-install HRESULT Install( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743818)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000a)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Install(); @@ -2014,7 +2009,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-runwizard HRESULT RunWizard( [in, optional] // BSTR dialogTitle, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000b)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult RunWizard([In, MarshalAs(UnmanagedType.BStr)] string dialogTitle = ""); @@ -2033,10 +2028,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_isbusy HRESULT get_IsBusy( VARIANT_BOOL // *retval ); - [DispId(1610743820)] + [DispId(0x6002000c)] new bool IsBusy { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743820)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000c)] get; } @@ -2051,7 +2046,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-uninstall HRESULT Uninstall( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743821)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000d)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Uninstall(); @@ -2061,12 +2056,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_allowsourceprompts HRESULT // put_AllowSourcePrompts( VARIANT_BOOL value ); - [DispId(1610743822)] + [DispId(0x6002000e)] new bool AllowSourcePrompts { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] [param: In] set; } @@ -2077,10 +2072,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_rebootrequiredbeforeinstallation HRESULT // get_RebootRequiredBeforeInstallation( VARIANT_BOOL *retval ); - [DispId(1610743823)] + [DispId(0x6002000f)] new bool RebootRequiredBeforeInstallation { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743823)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000f)] get; } @@ -2094,12 +2089,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller2-put_forcequiet HRESULT put_ForceQuiet( // VARIANT_BOOL value ); - [DispId(1610809345)] + [DispId(0x60030001)] new bool ForceQuiet { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] [param: In] set; } @@ -2110,12 +2105,12 @@ public static partial class WUApi /// True if the installer will attempt to close applications. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller3-get_attemptcloseappsifnecessary HRESULT // get_AttemptCloseAppsIfNecessary( [out] VARIANT_BOOL *retval ); - [DispId(1610874881)] + [DispId(0x60040001)] bool AttemptCloseAppsIfNecessary { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874881)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60040001)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874881)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60040001)] [param: In] set; } @@ -2124,7 +2119,7 @@ public static partial class WUApi /// Provides methods to finalize updates that were previously staged or installed. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateinstaller4 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateInstaller4")] - [ComImport, Guid("EF8208EA-2304-492D-9109-23813B0958E1")] + [ComImport, Guid("EF8208EA-2304-492D-9109-23813B0958E1"), CoClass(typeof(UpdateInstallerClass))] public interface IUpdateInstaller4 : IUpdateInstaller3 { /// @@ -2134,13 +2129,13 @@ public static partial class WUApi /// Returns the Unknown value if the client application has not set the property. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_clientapplicationid HRESULT // put_ClientApplicationID( BSTR value ); - [DispId(1610743809)] - new string ClientApplicationID + [DispId(0x60020001)] + new string? ClientApplicationID { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [return: MarshalAs(UnmanagedType.BStr)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743809)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020001)] [param: In, MarshalAs(UnmanagedType.BStr)] set; } @@ -2163,12 +2158,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_isforced HRESULT put_IsForced( // VARIANT_BOOL value ); - [DispId(1610743810)] + [DispId(0x60020002)] new bool IsForced { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020002)] [param: In] set; } @@ -2182,13 +2177,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parenthwnd HRESULT get_ParentHwnd( HWND // *retval ); - [ComAliasName("WUApiLib.wireHWND"), DispId(1610743811)] + [ComAliasName("WUApiLib.wireHWND"), DispId(0x60020003)] new HWND ParentHwnd { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [return: ComAliasName("WUApiLib.wireHWND")] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743811)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020003)] [param: In, ComAliasName("WUApiLib.wireHWND")] set; } @@ -2202,13 +2197,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_parentwindow HRESULT get_ParentWindow( // IUnknown **retval ); - [DispId(1610743812)] - new object parentWindow + [DispId(0x60020004)] + new object? parentWindow { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [return: MarshalAs(UnmanagedType.IUnknown)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743812)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020004)] [param: In, MarshalAs(UnmanagedType.IUnknown)] set; } @@ -2219,13 +2214,13 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_updates HRESULT get_Updates( // IUpdateCollection **retval ); - [DispId(1610743813)] + [DispId(0x60020005)] new IUpdateCollection Updates { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [return: MarshalAs(UnmanagedType.Interface)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743813)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020005)] [param: In, MarshalAs(UnmanagedType.Interface)] set; } @@ -2258,10 +2253,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-begininstall HRESULT BeginInstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743814)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020006)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginInstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Starts an asynchronous uninstallation of the updates. /// @@ -2291,10 +2286,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-beginuninstall HRESULT BeginUninstall( [in] // IUnknown *onProgressChanged, [in] IUnknown *onCompleted, [in] VARIANT state, [out] IInstallationJob **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743815)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020007)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationJob BeginUninstall([In, MarshalAs(UnmanagedType.IUnknown)] object onProgressChanged, - [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In, MarshalAs(UnmanagedType.IUnknown)] object onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object? state); /// Completes an asynchronous installation of the updates. /// The IInstallationJob interface that is returned by the BeginInstall method. @@ -2305,7 +2300,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-endinstall HRESULT EndInstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020008)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndInstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -2318,7 +2313,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-enduninstall HRESULT EndUninstall( [in] // IInstallationJob *value, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743817)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60020009)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult EndUninstall([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob value); @@ -2332,7 +2327,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-install HRESULT Install( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743818)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000a)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Install(); @@ -2351,7 +2346,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-runwizard HRESULT RunWizard( [in, optional] // BSTR dialogTitle, [out] IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743819)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000b)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult RunWizard([In, MarshalAs(UnmanagedType.BStr)] string dialogTitle = ""); @@ -2370,10 +2365,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_isbusy HRESULT get_IsBusy( VARIANT_BOOL // *retval ); - [DispId(1610743820)] + [DispId(0x6002000c)] new bool IsBusy { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743820)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000c)] get; } @@ -2388,7 +2383,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-uninstall HRESULT Uninstall( [out] // IInstallationResult **retval ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743821)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000d)] [return: MarshalAs(UnmanagedType.Interface)] new IInstallationResult Uninstall(); @@ -2398,12 +2393,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-put_allowsourceprompts HRESULT // put_AllowSourcePrompts( VARIANT_BOOL value ); - [DispId(1610743822)] + [DispId(0x6002000e)] new bool AllowSourcePrompts { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743822)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000e)] [param: In] set; } @@ -2414,10 +2409,10 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller-get_rebootrequiredbeforeinstallation HRESULT // get_RebootRequiredBeforeInstallation( VARIANT_BOOL *retval ); - [DispId(1610743823)] + [DispId(0x6002000f)] new bool RebootRequiredBeforeInstallation { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743823)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x6002000f)] get; } @@ -2431,12 +2426,12 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller2-put_forcequiet HRESULT put_ForceQuiet( // VARIANT_BOOL value ); - [DispId(1610809345)] + [DispId(0x60030001)] new bool ForceQuiet { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809345)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60030001)] [param: In] set; } @@ -2447,12 +2442,12 @@ public static partial class WUApi /// True if the installer will attempt to close applications. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller3-get_attemptcloseappsifnecessary HRESULT // get_AttemptCloseAppsIfNecessary( [out] VARIANT_BOOL *retval ); - [DispId(1610874881)] + [DispId(0x60040001)] new bool AttemptCloseAppsIfNecessary { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874881)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60040001)] get; - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874881)] + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60040001)] [param: In] set; } @@ -2475,8 +2470,8 @@ public static partial class WUApi /// Commit is safe to call prior to reboot for any other types of updates as well. /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller4-commit HRESULT Commit( DWORD dwFlags ); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874882)] - void Commit([In] uint dwFlags = 0); + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0x60040002)] + void Commit([In] uint dwFlags); } /// Restricts access to methods and properties of objects that implements the method of this interface. @@ -2571,7 +2566,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesearcher [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateSearcher")] - [ComImport, Guid("8F45ABF1-F9AE-4B95-A933-F0F66E5056EA"), CoClass(typeof(UpdateSearcher))] + [ComImport, Guid("8F45ABF1-F9AE-4B95-A933-F0F66E5056EA"), CoClass(typeof(UpdateSearcherClass))] public interface IUpdateSearcher { /// @@ -2680,7 +2675,7 @@ public static partial class WUApi [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] [return: MarshalAs(UnmanagedType.Interface)] ISearchJob BeginSearch([In, MarshalAs(UnmanagedType.BStr)] string criteria, - [In, MarshalAs(UnmanagedType.IUnknown)] ISearchCompletedCallback onCompleted, [In, MarshalAs(UnmanagedType.Struct)] object state); + [In] ISearchCompletedCallback onCompleted, [In, Optional, MarshalAs(UnmanagedType.Struct)] object? state); /// Completes an asynchronous search for updates. /// The ISearchJob interface that the BeginSearch method returns. @@ -2964,7 +2959,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesearcher2 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateSearcher2")] - [ComImport, Guid("4CBDCB2D-1589-4BEB-BD1C-3E582FF0ADD0"), CoClass(typeof(UpdateSearcher))] + [ComImport, Guid("4CBDCB2D-1589-4BEB-BD1C-3E582FF0ADD0"), CoClass(typeof(UpdateSearcherClass))] public interface IUpdateSearcher2 : IUpdateSearcher { /// @@ -3376,7 +3371,7 @@ public static partial class WUApi /// Searches for updates on a server. // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesearcher3 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateSearcher3")] - [ComImport, Guid("04C6895D-EAF2-4034-97F3-311DE9BE413A"), CoClass(typeof(UpdateSearcher))] + [ComImport, Guid("04C6895D-EAF2-4034-97F3-311DE9BE413A"), CoClass(typeof(UpdateSearcherClass))] public interface IUpdateSearcher3 : IUpdateSearcher2 { /// @@ -3845,7 +3840,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateservice-get_expirationdate HRESULT get_ExpirationDate( // DATE *retval ); [DispId(1610743810)] - DateTime ExpirationDate + DateTime? ExpirationDate { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] get; @@ -3924,7 +3919,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateservice-get_serviceid HRESULT get_ServiceID( BSTR // *retval ); [DispId(1610743816)] - string? ServiceID + string ServiceID { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743816)] [return: MarshalAs(UnmanagedType.BStr)] diff --git a/PInvoke/WUApi/WUApi4.cs b/PInvoke/WUApi/WUApi4.cs index 5fbbe637..81d214f0 100644 --- a/PInvoke/WUApi/WUApi4.cs +++ b/PInvoke/WUApi/WUApi4.cs @@ -10,7 +10,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateservicemanager [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateServiceManager")] - [ComImport, Guid("23857E3C-02BA-44A3-9423-B1C900805F37"), CoClass(typeof(UpdateServiceManager))] + [ComImport, Guid("23857E3C-02BA-44A3-9423-B1C900805F37"), CoClass(typeof(UpdateServiceManagerClass))] public interface IUpdateServiceManager { /// @@ -41,7 +41,7 @@ public static partial class WUApi // serviceID, [in] BSTR authorizationCabPath, [out] IUpdateService **retval ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] [return: MarshalAs(UnmanagedType.Interface)] - IUpdateService AddService([In, MarshalAs(UnmanagedType.BStr)] string serviceID, [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath); + IUpdateService AddService([In, MarshalAs(UnmanagedType.BStr)] string serviceID, [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath = ""); /// Registers a service with Automatic Updates. /// An identifier for the service to be registered. @@ -146,7 +146,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdateservicemanager2 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateServiceManager2")] - [ComImport, Guid("0BB8531D-7E8D-424F-986C-A0B8F60A3E7B"), CoClass(typeof(UpdateServiceManager))] + [ComImport, Guid("0BB8531D-7E8D-424F-986C-A0B8F60A3E7B"), CoClass(typeof(UpdateServiceManagerClass))] public interface IUpdateServiceManager2 : IUpdateServiceManager { /// @@ -177,7 +177,7 @@ public static partial class WUApi // serviceID, [in] BSTR authorizationCabPath, [out] IUpdateService **retval ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743810)] [return: MarshalAs(UnmanagedType.Interface)] - new IUpdateService AddService([In, MarshalAs(UnmanagedType.BStr)] string serviceID, [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath); + new IUpdateService AddService([In, MarshalAs(UnmanagedType.BStr)] string serviceID, [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath = ""); /// Registers a service with Automatic Updates. /// An identifier for the service to be registered. @@ -382,12 +382,12 @@ public static partial class WUApi /// /// /// - // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateservicemanager2-addservice2 HRESULT AddService2( [in] - // BSTR serviceID, [in] LONG flags, [in] BSTR authorizationCabPath, [out] IUpdateServiceRegistration **retval ); + // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateservicemanager2-addservice2 + // HRESULT AddService2( [in] BSTR serviceID, [in] LONG flags, [in] BSTR authorizationCabPath, [out] IUpdateServiceRegistration **retval ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610809347)] [return: MarshalAs(UnmanagedType.Interface)] - IUpdateServiceRegistration AddService2([In, MarshalAs(UnmanagedType.BStr)] string serviceID, [In] AddServiceFlag flags, - [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath); + IUpdateServiceRegistration AddService2([In, MarshalAs(UnmanagedType.BStr)] string serviceID, + [In] AddServiceFlag flags, [In, MarshalAs(UnmanagedType.BStr)] string authorizationCabPath); } /// Contains information about the registration state of a service. @@ -470,7 +470,7 @@ public static partial class WUApi /// to create the object. /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesession - [ComImport, Guid("816858A4-260D-4260-933A-2585F1ABC76B"), CoClass(typeof(UpdateSession))] + [ComImport, Guid("816858A4-260D-4260-933A-2585F1ABC76B"), CoClass(typeof(UpdateSessionClass))] public interface IUpdateSession { /// @@ -559,7 +559,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesession2 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateSession2")] - [ComImport, Guid("91CAF7B0-EB23-49ED-9937-C52D817F46F7"), CoClass(typeof(UpdateSession))] + [ComImport, Guid("91CAF7B0-EB23-49ED-9937-C52D817F46F7"), CoClass(typeof(UpdateSessionClass))] public interface IUpdateSession2 : IUpdateSession { /// @@ -679,7 +679,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatesession3 [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IUpdateSession3")] - [ComImport, Guid("918EFD1E-B5D8-4C90-8540-AEB9BDC56F9D"), CoClass(typeof(UpdateSession))] + [ComImport, Guid("918EFD1E-B5D8-4C90-8540-AEB9BDC56F9D"), CoClass(typeof(UpdateSessionClass))] public interface IUpdateSession3 : IUpdateSession2 { /// @@ -868,7 +868,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iwebproxy [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IWebProxy")] - [ComImport, Guid("174C81FE-AECD-4DAE-B8A0-2C6318DD86A8"), CoClass(typeof(WebProxy))] + [ComImport, Guid("174C81FE-AECD-4DAE-B8A0-2C6318DD86A8"), CoClass(typeof(WebProxyClass))] public interface IWebProxy { /// @@ -1880,7 +1880,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -2882,7 +2882,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -3931,7 +3931,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -4993,7 +4993,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. @@ -6082,7 +6082,7 @@ public static partial class WUApi // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdate-copyfromcache HRESULT CopyFromCache( [in] BSTR path, // [in] VARIANT_BOOL toExtractCabFiles ); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610743850)] - new void CopyFromCache([In][MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); + new void CopyFromCache([In, MarshalAs(UnmanagedType.BStr)] string path, [In] bool toExtractCabFiles); /// /// Gets the suggested download priority of the update. diff --git a/PInvoke/WUApi/WUApi5.cs b/PInvoke/WUApi/WUApi5.cs index 974aaa79..4b6d8fd8 100644 --- a/PInvoke/WUApi/WUApi5.cs +++ b/PInvoke/WUApi/WUApi5.cs @@ -172,7 +172,7 @@ public static partial class WUApi /// // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iwindowsupdateagentinfo [PInvokeData("wuapi.h", MSDNShortId = "NN:wuapi.IWindowsUpdateAgentInfo")] - [ComImport, Guid("85713FA1-7796-4FA2-BE3B-E2D6124DD373"), CoClass(typeof(WindowsUpdateAgentInfo))] + [ComImport, Guid("85713FA1-7796-4FA2-BE3B-E2D6124DD373"), CoClass(typeof(WindowsUpdateAgentInfoClass))] public interface IWindowsUpdateAgentInfo { /// Retrieves version information about Windows Update Agent (WUA). @@ -222,71 +222,71 @@ public static partial class WUApi /// CLSID_AutomaticUpdates /// [ComImport, Guid("BFE18E9C-6D87-4450-B37C-E02F0B373803"), ClassInterface(ClassInterfaceType.None)] - public class AutomaticUpdates { } + public class AutomaticUpdatesClass { } /// /// CLSID_InstallationAgent /// [ComImport, Guid("317E92FC-1679-46FD-A0B5-F08914DD8623"), ClassInterface(ClassInterfaceType.None)] - public class InstallationAgent { } + public class InstallationAgentClass { } /// /// CLSID_StringCollection /// [ComImport, Guid("72C97D74-7C3B-40AE-B77D-ABDB22EBA6FB"), ClassInterface(ClassInterfaceType.None)] - public class StringCollection { } + public class StringCollectionClass { } /// /// CLSID_SystemInformation /// [ComImport, Guid("C01B9BA0-BEA7-41BA-B604-D0A36F469133"), ClassInterface(ClassInterfaceType.None)] - public class SystemInformation { } + public class SystemInformationClass { } /// /// CLSID_UpdateCollection /// [ComImport, Guid("13639463-00DB-4646-803D-528026140D88"), ClassInterface(ClassInterfaceType.None)] - public class UpdateCollection { } + public class UpdateCollectionClass { } /// /// CLSID_UpdateDownloader /// [ComImport, Guid("5BAF654A-5A07-4264-A255-9FF54C7151E7"), ClassInterface(ClassInterfaceType.None)] - public class UpdateDownloader { } + public class UpdateDownloaderClass { } /// /// CLSID_UpdateInstaller /// [ComImport, Guid("D2E0FE7F-D23E-48E1-93C0-6FA8CC346474"), ClassInterface(ClassInterfaceType.None)] - public class UpdateInstaller { } + public class UpdateInstallerClass { } /// /// CLSID_UpdateSearcher /// [ComImport, Guid("B699E5E8-67FF-4177-88B0-3684A3388BFB"), ClassInterface(ClassInterfaceType.None)] - public class UpdateSearcher { } + public class UpdateSearcherClass { } /// /// CLSID_UpdateServiceManager /// [ComImport, Guid("F8D253D9-89A4-4DAA-87B6-1168369F0B21"), ClassInterface(ClassInterfaceType.None)] - public class UpdateServiceManager { } + public class UpdateServiceManagerClass { } /// /// CLSID_UpdateSession /// [ComImport, Guid("4CB43D7F-7EEE-4906-8698-60DA1C38F2FE"), ClassInterface(ClassInterfaceType.None)] - public class UpdateSession { } + public class UpdateSessionClass { } /// /// CLSID_WebProxy /// [ComImport, Guid("650503CF-9108-4DDC-A2CE-6C2341E1C582"), ClassInterface(ClassInterfaceType.None)] - public class WebProxy { } + public class WebProxyClass { } /// /// CLSID_WindowsUpdateAgentInfo /// [ComImport, Guid("C2E88C2F-6F5B-4AAA-894B-55C847AD3A2D"), ClassInterface(ClassInterfaceType.None)] - public class WindowsUpdateAgentInfo { } + public class WindowsUpdateAgentInfoClass { } } \ No newline at end of file diff --git a/PInvoke/WUApi/WUError.cs b/PInvoke/WUApi/WUError.cs new file mode 100644 index 00000000..f2879fd3 --- /dev/null +++ b/PInvoke/WUApi/WUError.cs @@ -0,0 +1,1422 @@ +namespace Vanara.PInvoke; + +/// PInvoke API (methods, structures and constants) imported from Windows Update API. +public static partial class WUApi +{ + static WUApi() + { + StaticFieldValueHash.AddFields(Lib_WUApi); + //ErrorHelper.AddErrorMessageLookupFunction(); + } + + /// + /// HRESULT error codes from wuerror.h. These are the same as the Windows Update error codes. + /// + [PInvokeData("wuerror.h")] + public enum WUError + { + /// Windows Update Agent was stopped successfully. + WU_S_SERVICE_STOP = 0x00240001, + + /// Windows Update Agent updated itself. + WU_S_SELFUPDATE = 0x00240002, + + /// Operation completed successfully but there were errors applying the updates. + WU_S_UPDATE_ERROR = 0x00240003, + + /// A callback was marked to be disconnected later because the request to disconnect the operation came while a callback was executing. + WU_S_MARKED_FOR_DISCONNECT = 0x00240004, + + /// The system must be restarted to complete installation of the update. + WU_S_REBOOT_REQUIRED = 0x00240005, + + /// The update to be installed is already installed on the system. + WU_S_ALREADY_INSTALLED = 0x00240006, + + /// The update to be removed is not installed on the system. + WU_S_ALREADY_UNINSTALLED = 0x00240007, + + /// The update to be downloaded has already been downloaded. + WU_S_ALREADY_DOWNLOADED = 0x00240008, + + /// The operation completed successfully, but some updates were skipped because the system is running on batteries. + WU_S_SOME_UPDATES_SKIPPED_ON_BATTERY = 0x00240009, + + /// The update to be reverted is not present on the system. + WU_S_ALREADY_REVERTED = 0x0024000A, + + /// The operation is skipped because the update service does not support the requested search criteria. + WU_S_SEARCH_CRITERIA_NOT_SUPPORTED = 0x00240010, + + /// The installation operation for the update is still in progress. + WU_S_UH_INSTALLSTILLPENDING = 0x00242015, + + /// The actual download size has been calculated by the handler. + WU_S_UH_DOWNLOAD_SIZE_CALCULATED = 0x00242016, + + /// No operation was required by the server-initiated healing server response. + WU_S_SIH_NOOP = 0x00245001, + + /// The update to be downloaded is already being downloaded. + WU_S_DM_ALREADYDOWNLOADING = 0x00246001, + + /// Metadata verification was skipped by enforcement mode. + WU_S_METADATA_SKIPPED_BY_ENFORCEMENTMODE = 0x00247101, + + /// A server configuration refresh resulted in metadata signature verification to be ignored. + WU_S_METADATA_IGNORED_SIGNATURE_VERIFICATION = 0x00247102, + + /// Search operation completed successfully but one or more services were shedding load. + WU_S_SEARCH_LOAD_SHEDDING = 0x00248001, + + /// There was no need to retrieve an AAD device ticket. + WU_S_AAD_DEVICE_TICKET_NOT_NEEDED = 0x00248002, + + /// Windows Update Agent was unable to provide the service. + WU_E_NO_SERVICE = unchecked((int)0x80240001), + + /// The maximum capacity of the service was exceeded. + WU_E_MAX_CAPACITY_REACHED = unchecked((int)0x80240002), + + /// An ID cannot be found. + WU_E_UNKNOWN_ID = unchecked((int)0x80240003), + + /// The object could not be initialized. + WU_E_NOT_INITIALIZED = unchecked((int)0x80240004), + + /// The update handler requested a byte range overlapping a previously requested range. + WU_E_RANGEOVERLAP = unchecked((int)0x80240005), + + /// The requested number of byte ranges exceeds the maximum number (2^31 - 1). + WU_E_TOOMANYRANGES = unchecked((int)0x80240006), + + /// The index to a collection was invalid. + WU_E_INVALIDINDEX = unchecked((int)0x80240007), + + /// The key for the item queried could not be found. + WU_E_ITEMNOTFOUND = unchecked((int)0x80240008), + + /// Another conflicting operation was in progress. Some operations such as installation cannot be performed twice simultaneously. + WU_E_OPERATIONINPROGRESS = unchecked((int)0x80240009), + + /// Cancellation of the operation was not allowed. + WU_E_COULDNOTCANCEL = unchecked((int)0x8024000A), + + /// Operation was cancelled. + WU_E_CALL_CANCELLED = unchecked((int)0x8024000B), + + /// No operation was required. + WU_E_NOOP = unchecked((int)0x8024000C), + + /// Windows Update Agent could not find required information in the update's XML data. + WU_E_XML_MISSINGDATA = unchecked((int)0x8024000D), + + /// Windows Update Agent found invalid information in the update's XML data. + WU_E_XML_INVALID = unchecked((int)0x8024000E), + + /// Circular update relationships were detected in the metadata. + WU_E_CYCLE_DETECTED = unchecked((int)0x8024000F), + + /// Update relationships too deep to evaluate were evaluated. + WU_E_TOO_DEEP_RELATION = unchecked((int)0x80240010), + + /// An invalid update relationship was detected. + WU_E_INVALID_RELATIONSHIP = unchecked((int)0x80240011), + + /// An invalid registry value was read. + WU_E_REG_VALUE_INVALID = unchecked((int)0x80240012), + + /// Operation tried to add a duplicate item to a list. + WU_E_DUPLICATE_ITEM = unchecked((int)0x80240013), + + /// Updates requested for install are not installable by caller. + WU_E_INVALID_INSTALL_REQUESTED = unchecked((int)0x80240014), + + /// Operation tried to install while another installation was in progress or the system was pending a mandatory restart. + WU_E_INSTALL_NOT_ALLOWED = unchecked((int)0x80240016), + + /// Operation was not performed because there are no applicable updates. + WU_E_NOT_APPLICABLE = unchecked((int)0x80240017), + + /// Operation failed because a required user token is missing. + WU_E_NO_USERTOKEN = unchecked((int)0x80240018), + + /// An exclusive update cannot be installed with other updates at the same time. + WU_E_EXCLUSIVE_INSTALL_CONFLICT = unchecked((int)0x80240019), + + /// A policy value was not set. + WU_E_POLICY_NOT_SET = unchecked((int)0x8024001A), + + /// The operation could not be performed because the Windows Update Agent is self-updating. + WU_E_SELFUPDATE_IN_PROGRESS = unchecked((int)0x8024001B), + + /// An update contains invalid metadata. + WU_E_INVALID_UPDATE = unchecked((int)0x8024001D), + + /// Operation did not complete because the service or system was being shut down. + WU_E_SERVICE_STOP = unchecked((int)0x8024001E), + + /// Operation did not complete because the network connection was unavailable. + WU_E_NO_CONNECTION = unchecked((int)0x8024001F), + + /// Operation did not complete because there is no logged-on interactive user. + WU_E_NO_INTERACTIVE_USER = unchecked((int)0x80240020), + + /// Operation did not complete because it timed out. + WU_E_TIME_OUT = unchecked((int)0x80240021), + + /// Operation failed for all the updates. + WU_E_ALL_UPDATES_FAILED = unchecked((int)0x80240022), + + /// The license terms for all updates were declined. + WU_E_EULAS_DECLINED = unchecked((int)0x80240023), + + /// There are no updates. + WU_E_NO_UPDATE = unchecked((int)0x80240024), + + /// Group Policy settings prevented access to Windows Update. + WU_E_USER_ACCESS_DISABLED = unchecked((int)0x80240025), + + /// The type of update is invalid. + WU_E_INVALID_UPDATE_TYPE = unchecked((int)0x80240026), + + /// The URL exceeded the maximum length. + WU_E_URL_TOO_LONG = unchecked((int)0x80240027), + + /// The update could not be uninstalled because the request did not originate from a WSUS server. + WU_E_UNINSTALL_NOT_ALLOWED = unchecked((int)0x80240028), + + /// Search may have missed some updates before there is an unlicensed application on the system. + WU_E_INVALID_PRODUCT_LICENSE = unchecked((int)0x80240029), + + /// A component required to detect applicable updates was missing. + WU_E_MISSING_HANDLER = unchecked((int)0x8024002A), + + /// An operation did not complete because it requires a newer version of server. + WU_E_LEGACYSERVER = unchecked((int)0x8024002B), + + /// A delta-compressed update could not be installed because it required the source. + WU_E_BIN_SOURCE_ABSENT = unchecked((int)0x8024002C), + + /// A full-file update could not be installed because it required the source. + WU_E_SOURCE_ABSENT = unchecked((int)0x8024002D), + + /// Access to an unmanaged server is not allowed. + WU_E_WU_DISABLED = unchecked((int)0x8024002E), + + /// Operation did not complete because the DisableWindowsUpdateAccess policy was set. + WU_E_CALL_CANCELLED_BY_POLICY = unchecked((int)0x8024002F), + + /// The format of the proxy list was invalid. + WU_E_INVALID_PROXY_SERVER = unchecked((int)0x80240030), + + /// The file is in the wrong format. + WU_E_INVALID_FILE = unchecked((int)0x80240031), + + /// The search criteria string was invalid. + WU_E_INVALID_CRITERIA = unchecked((int)0x80240032), + + /// License terms could not be downloaded. + WU_E_EULA_UNAVAILABLE = unchecked((int)0x80240033), + + /// Update failed to download. + WU_E_DOWNLOAD_FAILED = unchecked((int)0x80240034), + + /// The update was not processed. + WU_E_UPDATE_NOT_PROCESSED = unchecked((int)0x80240035), + + /// The object's current state did not allow the operation. + WU_E_INVALID_OPERATION = unchecked((int)0x80240036), + + /// The functionality for the operation is not supported. + WU_E_NOT_SUPPORTED = unchecked((int)0x80240037), + + /// The downloaded file has an unexpected content type. + WU_E_WINHTTP_INVALID_FILE = unchecked((int)0x80240038), + + /// Agent is asked by server to resync too many times. + WU_E_TOO_MANY_RESYNC = unchecked((int)0x80240039), + + /// WUA API method does not run on Server Core installation. + WU_E_NO_SERVER_CORE_SUPPORT = unchecked((int)0x80240040), + + /// Service is not available while sysprep is running. + WU_E_SYSPREP_IN_PROGRESS = unchecked((int)0x80240041), + + /// The update service is no longer registered with AU. + WU_E_UNKNOWN_SERVICE = unchecked((int)0x80240042), + + /// There is no support for WUA UI. + WU_E_NO_UI_SUPPORT = unchecked((int)0x80240043), + + /// Only administrators can perform this operation on per-machine updates. + WU_E_PER_MACHINE_UPDATE_ACCESS_DENIED = unchecked((int)0x80240044), + + /// A search was attempted with a scope that is not currently supported for this type of search. + WU_E_UNSUPPORTED_SEARCHSCOPE = unchecked((int)0x80240045), + + /// The URL does not point to a file. + WU_E_BAD_FILE_URL = unchecked((int)0x80240046), + + /// The update could not be reverted. + WU_E_REVERT_NOT_ALLOWED = unchecked((int)0x80240047), + + /// The featured update notification info returned by the server is invalid. + WU_E_INVALID_NOTIFICATION_INFO = unchecked((int)0x80240048), + + /// The data is out of range. + WU_E_OUTOFRANGE = unchecked((int)0x80240049), + + /// Windows Update agent operations are not available while OS setup is running. + WU_E_SETUP_IN_PROGRESS = unchecked((int)0x8024004A), + + /// An orphaned downloadjob was found with no active callers. + WU_E_ORPHANED_DOWNLOAD_JOB = unchecked((int)0x8024004B), + + /// An update could not be installed because the system battery power level is too low. + WU_E_LOW_BATTERY = unchecked((int)0x8024004C), + + /// The downloaded infrastructure file is incorrectly formatted. + WU_E_INFRASTRUCTUREFILE_INVALID_FORMAT = unchecked((int)0x8024004D), + + /// The infrastructure file must be downloaded using strong SSL. + WU_E_INFRASTRUCTUREFILE_REQUIRES_SSL = unchecked((int)0x8024004E), + + /// A discovery call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_DISCOVERY = unchecked((int)0x8024004F), + + /// A search call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_SEARCH = unchecked((int)0x80240050), + + /// A download call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_DOWNLOAD = unchecked((int)0x80240051), + + /// An install call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_INSTALL = unchecked((int)0x80240052), + + /// An unspecified call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_OTHER = unchecked((int)0x80240053), + + /// An interactive user cancelled this operation, which was started from the Windows Update Agent UI. + WU_E_INTERACTIVE_CALL_CANCELLED = unchecked((int)0x80240054), + + /// Automatic Updates cancelled this operation because it applies to an update that is no longer applicable to this computer. + WU_E_AU_CALL_CANCELLED = unchecked((int)0x80240055), + + /// This version or edition of the operating system doesn't support the needed functionality. + WU_E_SYSTEM_UNSUPPORTED = unchecked((int)0x80240056), + + /// The requested update download or install handler, or update applicability expression evaluator, is not provided by this Agent plugin. + WU_E_NO_SUCH_HANDLER_PLUGIN = unchecked((int)0x80240057), + + /// The requested serialization version is not supported. + WU_E_INVALID_SERIALIZATION_VERSION = unchecked((int)0x80240058), + + /// The current network cost does not meet the conditions set by the network cost policy. + WU_E_NETWORK_COST_EXCEEDS_POLICY = unchecked((int)0x80240059), + + /// The call is cancelled because it applies to an update that is hidden (no longer applicable to this computer). + WU_E_CALL_CANCELLED_BY_HIDE = unchecked((int)0x8024005A), + + /// The call is cancelled because it applies to an update that is invalid (no longer applicable to this computer). + WU_E_CALL_CANCELLED_BY_INVALID = unchecked((int)0x8024005B), + + /// The specified volume id is invalid. + WU_E_INVALID_VOLUMEID = unchecked((int)0x8024005C), + + /// The specified volume id is unrecognized by the system. + WU_E_UNRECOGNIZED_VOLUMEID = unchecked((int)0x8024005D), + + /// The installation extended error code is not specified. + WU_E_EXTENDEDERROR_NOTSET = unchecked((int)0x8024005E), + + /// The installation extended error code is set to general fail. + WU_E_EXTENDEDERROR_FAILED = unchecked((int)0x8024005F), + + /// A service registration call contributed to a non-zero operation count at idle timer shutdown. + WU_E_IDLESHUTDOWN_OPCOUNT_SERVICEREGISTRATION = unchecked((int)0x80240060), + + /// Signature validation of the file fails to find valid SHA2+ signature on MS signed payload. + WU_E_FILETRUST_SHA2SIGNATURE_MISSING = unchecked((int)0x80240061), + + /// The update is not in the servicing approval list. + WU_E_UPDATE_NOT_APPROVED = unchecked((int)0x80240062), + + /// The search call was cancelled by another interactive search against the same service. + WU_E_CALL_CANCELLED_BY_INTERACTIVE_SEARCH = unchecked((int)0x80240063), + + /// Resume of install job not allowed due to another installation in progress. + WU_E_INSTALL_JOB_RESUME_NOT_ALLOWED = unchecked((int)0x80240064), + + /// Resume of install job not allowed because job is not suspended. + WU_E_INSTALL_JOB_NOT_SUSPENDED = unchecked((int)0x80240065), + + /// User context passed to installation from caller with insufficient privileges. + WU_E_INSTALL_USERCONTEXT_ACCESSDENIED = unchecked((int)0x80240066), + + /// An operation failed due to reasons not covered by another error code. + WU_E_UNEXPECTED = unchecked((int)0x80240FFF), + + /// Search may have missed some updates because the Windows Installer is less than version 3.1. + WU_E_MSI_WRONG_VERSION = unchecked((int)0x80241001), + + /// Search may have missed some updates because the Windows Installer is not configured. + WU_E_MSI_NOT_CONFIGURED = unchecked((int)0x80241002), + + /// Search may have missed some updates because policy has disabled Windows Installer patching. + WU_E_MSP_DISABLED = unchecked((int)0x80241003), + + /// An update could not be applied because the application is installed per-user. + WU_E_MSI_WRONG_APP_CONTEXT = unchecked((int)0x80241004), + + /// Search may have missed some updates because the Windows Installer is less than version 3.1. + WU_E_MSI_NOT_PRESENT = unchecked((int)0x80241005), + + /// Search may have missed some updates because there was a failure of the Windows Installer. + WU_E_MSP_UNEXPECTED = unchecked((int)0x80241FFF), + + /// WU_E_PT_SOAPCLIENT_* error codes map to the SOAPCLIENT_ERROR enum of the ATL Server Library. + WU_E_PT_SOAPCLIENT_BASE = unchecked((int)0x80244000), + + /// Same as SOAPCLIENT_INITIALIZE_ERROR - initialization of the SOAP client failed, possibly because of an MSXML installation failure. + WU_E_PT_SOAPCLIENT_INITIALIZE = unchecked((int)0x80244001), + + /// Same as SOAPCLIENT_OUTOFMEMORY - SOAP client failed because it ran out of memory. + WU_E_PT_SOAPCLIENT_OUTOFMEMORY = unchecked((int)0x80244002), + + /// Same as SOAPCLIENT_GENERATE_ERROR - SOAP client failed to generate the request. + WU_E_PT_SOAPCLIENT_GENERATE = unchecked((int)0x80244003), + + /// Same as SOAPCLIENT_CONNECT_ERROR - SOAP client failed to connect to the server. + WU_E_PT_SOAPCLIENT_CONNECT = unchecked((int)0x80244004), + + /// Same as SOAPCLIENT_SEND_ERROR - SOAP client failed to send a message for reasons of WU_E_WINHTTP_* error codes. + WU_E_PT_SOAPCLIENT_SEND = unchecked((int)0x80244005), + + /// Same as SOAPCLIENT_SERVER_ERROR - SOAP client failed because there was a server error. + WU_E_PT_SOAPCLIENT_SERVER = unchecked((int)0x80244006), + + /// Same as SOAPCLIENT_SOAPFAULT - SOAP client failed because there was a SOAP fault for reasons of WU_E_PT_SOAP_* error codes. + WU_E_PT_SOAPCLIENT_SOAPFAULT = unchecked((int)0x80244007), + + /// Same as SOAPCLIENT_PARSEFAULT_ERROR - SOAP client failed to parse a SOAP fault. + WU_E_PT_SOAPCLIENT_PARSEFAULT = unchecked((int)0x80244008), + + /// Same as SOAPCLIENT_READ_ERROR - SOAP client failed while reading the response from the server. + WU_E_PT_SOAPCLIENT_READ = unchecked((int)0x80244009), + + /// Same as SOAPCLIENT_PARSE_ERROR - SOAP client failed to parse the response from the server. + WU_E_PT_SOAPCLIENT_PARSE = unchecked((int)0x8024400A), + + /// Same as SOAP_E_VERSION_MISMATCH - SOAP client found an unrecognizable namespace for the SOAP envelope. + WU_E_PT_SOAP_VERSION = unchecked((int)0x8024400B), + + /// Same as SOAP_E_MUST_UNDERSTAND - SOAP client was unable to understand a header. + WU_E_PT_SOAP_MUST_UNDERSTAND = unchecked((int)0x8024400C), + + /// Same as SOAP_E_CLIENT - SOAP client found the message was malformed; fix before resending. + WU_E_PT_SOAP_CLIENT = unchecked((int)0x8024400D), + + /// Same as SOAP_E_SERVER - The SOAP message could not be processed due to a server error; resend later. + WU_E_PT_SOAP_SERVER = unchecked((int)0x8024400E), + + /// There was an unspecified Windows Management Instrumentation (WMI) error. + WU_E_PT_WMI_ERROR = unchecked((int)0x8024400F), + + /// The number of round trips to the server exceeded the maximum limit. + WU_E_PT_EXCEEDED_MAX_SERVER_TRIPS = unchecked((int)0x80244010), + + /// WUServer policy value is missing in the registry. + WU_E_PT_SUS_SERVER_NOT_SET = unchecked((int)0x80244011), + + /// Initialization failed because the object was already initialized. + WU_E_PT_DOUBLE_INITIALIZATION = unchecked((int)0x80244012), + + /// The computer name could not be determined. + WU_E_PT_INVALID_COMPUTER_NAME = unchecked((int)0x80244013), + + /// The reply from the server indicates that the server was changed or the cookie was invalid; refresh the state of the internal cache and retry. + WU_E_PT_REFRESH_CACHE_REQUIRED = unchecked((int)0x80244015), + + /// Same as HTTP status 400 - the server could not process the request due to invalid syntax. + WU_E_PT_HTTP_STATUS_BAD_REQUEST = unchecked((int)0x80244016), + + /// Same as HTTP status 401 - the requested resource requires user authentication. + WU_E_PT_HTTP_STATUS_DENIED = unchecked((int)0x80244017), + + /// Same as HTTP status 403 - server understood the request, but declined to fulfill it. + WU_E_PT_HTTP_STATUS_FORBIDDEN = unchecked((int)0x80244018), + + /// Same as HTTP status 404 - the server cannot find the requested URI (Uniform Resource Identifier). + WU_E_PT_HTTP_STATUS_NOT_FOUND = unchecked((int)0x80244019), + + /// Same as HTTP status 405 - the HTTP method is not allowed. + WU_E_PT_HTTP_STATUS_BAD_METHOD = unchecked((int)0x8024401A), + + /// Same as HTTP status 407 - proxy authentication is required. + WU_E_PT_HTTP_STATUS_PROXY_AUTH_REQ = unchecked((int)0x8024401B), + + /// Same as HTTP status 408 - the server timed out waiting for the request. + WU_E_PT_HTTP_STATUS_REQUEST_TIMEOUT = unchecked((int)0x8024401C), + + /// Same as HTTP status 409 - the request was not completed due to a conflict with the current state of the resource. + WU_E_PT_HTTP_STATUS_CONFLICT = unchecked((int)0x8024401D), + + /// Same as HTTP status 410 - requested resource is no longer available at the server. + WU_E_PT_HTTP_STATUS_GONE = unchecked((int)0x8024401E), + + /// Same as HTTP status 500 - an error internal to the server prevented fulfilling the request. + WU_E_PT_HTTP_STATUS_SERVER_ERROR = unchecked((int)0x8024401F), + + /// Same as HTTP status 500 - server does not support the functionality required to fulfill the request. + WU_E_PT_HTTP_STATUS_NOT_SUPPORTED = unchecked((int)0x80244020), + + /// Same as HTTP status 502 - the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. + WU_E_PT_HTTP_STATUS_BAD_GATEWAY = unchecked((int)0x80244021), + + /// Same as HTTP status 503 - the service is temporarily overloaded. + WU_E_PT_HTTP_STATUS_SERVICE_UNAVAIL = unchecked((int)0x80244022), + + /// Same as HTTP status 503 - the request was timed out waiting for a gateway. + WU_E_PT_HTTP_STATUS_GATEWAY_TIMEOUT = unchecked((int)0x80244023), + + /// Same as HTTP status 505 - the server does not support the HTTP protocol version used for the request. + WU_E_PT_HTTP_STATUS_VERSION_NOT_SUP = unchecked((int)0x80244024), + + /// Operation failed due to a changed file location; refresh internal state and resend. + WU_E_PT_FILE_LOCATIONS_CHANGED = unchecked((int)0x80244025), + + /// Operation failed because Windows Update Agent does not support registration with a non-WSUS server. + WU_E_PT_REGISTRATION_NOT_SUPPORTED = unchecked((int)0x80244026), + + /// The server returned an empty authentication information list. + WU_E_PT_NO_AUTH_PLUGINS_REQUESTED = unchecked((int)0x80244027), + + /// Windows Update Agent was unable to create any valid authentication cookies. + WU_E_PT_NO_AUTH_COOKIES_CREATED = unchecked((int)0x80244028), + + /// A configuration property value was wrong. + WU_E_PT_INVALID_CONFIG_PROP = unchecked((int)0x80244029), + + /// A configuration property value was missing. + WU_E_PT_CONFIG_PROP_MISSING = unchecked((int)0x8024402A), + + /// The HTTP request could not be completed and the reason did not correspond to any of the WU_E_PT_HTTP_* error codes. + WU_E_PT_HTTP_STATUS_NOT_MAPPED = unchecked((int)0x8024402B), + + /// Same as ERROR_WINHTTP_NAME_NOT_RESOLVED - the proxy server or target server name cannot be resolved. + WU_E_PT_WINHTTP_NAME_NOT_RESOLVED = unchecked((int)0x8024402C), + + /// The server is shedding load. + WU_E_PT_LOAD_SHEDDING = unchecked((int)0x8024402D), + + /// Windows Update Agent failed to download a redirector cabinet file with a new redirectorId value from the server during the recovery. + WU_E_PT_SAME_REDIR_ID = unchecked((int)0x8024502D), + + /// A redirector recovery action did not complete because the server is managed. + WU_E_PT_NO_MANAGED_RECOVER = unchecked((int)0x8024502E), + + /// External cab file processing completed with some errors. + WU_E_PT_ECP_SUCCEEDED_WITH_ERRORS = unchecked((int)0x8024402F), + + /// The external cab processor initialization did not complete. + WU_E_PT_ECP_INIT_FAILED = unchecked((int)0x80244030), + + /// The format of a metadata file was invalid. + WU_E_PT_ECP_INVALID_FILE_FORMAT = unchecked((int)0x80244031), + + /// External cab processor found invalid metadata. + WU_E_PT_ECP_INVALID_METADATA = unchecked((int)0x80244032), + + /// The file digest could not be extracted from an external cab file. + WU_E_PT_ECP_FAILURE_TO_EXTRACT_DIGEST = unchecked((int)0x80244033), + + /// An external cab file could not be decompressed. + WU_E_PT_ECP_FAILURE_TO_DECOMPRESS_CAB_FILE = unchecked((int)0x80244034), + + /// External cab processor was unable to get file locations. + WU_E_PT_ECP_FILE_LOCATION_ERROR = unchecked((int)0x80244035), + + /// The server does not support category-specific search; Full catalog search has to be issued instead. + WU_E_PT_CATALOG_SYNC_REQUIRED = unchecked((int)0x80240436), + + /// There was a problem authorizing with the service. + WU_E_PT_SECURITY_VERIFICATION_FAILURE = unchecked((int)0x80240437), + + /// There is no route or network connectivity to the endpoint. + WU_E_PT_ENDPOINT_UNREACHABLE = unchecked((int)0x80240438), + + /// The data received does not meet the data contract expectations. + WU_E_PT_INVALID_FORMAT = unchecked((int)0x80240439), + + /// The url is invalid. + WU_E_PT_INVALID_URL = unchecked((int)0x8024043A), + + /// Unable to load NWS runtime. + WU_E_PT_NWS_NOT_LOADED = unchecked((int)0x8024043B), + + /// The proxy auth scheme is not supported. + WU_E_PT_PROXY_AUTH_SCHEME_NOT_SUPPORTED = unchecked((int)0x8024043C), + + /// The requested service property is not available. + WU_E_SERVICEPROP_NOTAVAIL = unchecked((int)0x8024043D), + + /// The endpoint provider plugin requires online refresh. + WU_E_PT_ENDPOINT_REFRESH_REQUIRED = unchecked((int)0x8024043E), + + /// A URL for the requested service endpoint is not available. + WU_E_PT_ENDPOINTURL_NOTAVAIL = unchecked((int)0x8024043F), + + /// The connection to the service endpoint died. + WU_E_PT_ENDPOINT_DISCONNECTED = unchecked((int)0x80240440), + + /// The operation is invalid because protocol talker is in an inappropriate state. + WU_E_PT_INVALID_OPERATION = unchecked((int)0x80240441), + + /// The object is in a faulted state due to a previous error. + WU_E_PT_OBJECT_FAULTED = unchecked((int)0x80240442), + + /// The operation would lead to numeric overflow. + WU_E_PT_NUMERIC_OVERFLOW = unchecked((int)0x80240443), + + /// The operation was aborted. + WU_E_PT_OPERATION_ABORTED = unchecked((int)0x80240444), + + /// The operation was abandoned. + WU_E_PT_OPERATION_ABANDONED = unchecked((int)0x80240445), + + /// A quota was exceeded. + WU_E_PT_QUOTA_EXCEEDED = unchecked((int)0x80240446), + + /// The information was not available in the specified language. + WU_E_PT_NO_TRANSLATION_AVAILABLE = unchecked((int)0x80240447), + + /// The address is already being used. + WU_E_PT_ADDRESS_IN_USE = unchecked((int)0x80240448), + + /// The address is not valid for this context. + WU_E_PT_ADDRESS_NOT_AVAILABLE = unchecked((int)0x80240449), + + /// Unrecognized error occurred in the Windows Web Services framework. + WU_E_PT_OTHER = unchecked((int)0x8024044A), + + /// A security operation failed in the Windows Web Services framework. + WU_E_PT_SECURITY_SYSTEM_FAILURE = unchecked((int)0x8024044B), + + /// The client is data boundary restricted and needs to talk to a restricted endpoint. + WU_E_PT_DATA_BOUNDARY_RESTRICTED = unchecked((int)0x80244100), + + /// The client hit an error in retrievingg AAD device ticket. + WU_E_PT_GENERAL_AAD_CLIENT_ERROR = unchecked((int)0x80244101), + + /// A communication error not covered by another WU_E_PT_* error code. + WU_E_PT_UNEXPECTED = unchecked((int)0x80244FFF), + + /// The redirector XML document could not be loaded into the DOM class. + WU_E_REDIRECTOR_LOAD_XML = unchecked((int)0x80245001), + + /// The redirector XML document is missing some required information. + WU_E_REDIRECTOR_S_FALSE = unchecked((int)0x80245002), + + /// The redirectorId in the downloaded redirector cab is less than in the cached cab. + WU_E_REDIRECTOR_ID_SMALLER = unchecked((int)0x80245003), + + /// The service ID is not supported in the service environment. + WU_E_REDIRECTOR_UNKNOWN_SERVICE = unchecked((int)0x80245004), + + /// The response from the redirector server had an unsupported content type. + WU_E_REDIRECTOR_UNSUPPORTED_CONTENTTYPE = unchecked((int)0x80245005), + + /// The response from the redirector server had an error status or was invalid. + WU_E_REDIRECTOR_INVALID_RESPONSE = unchecked((int)0x80245006), + + /// The maximum number of name value pairs was exceeded by the attribute provider. + WU_E_REDIRECTOR_ATTRPROVIDER_EXCEEDED_MAX_NAMEVALUE = unchecked((int)0x80245008), + + /// The name received from the attribute provider was invalid. + WU_E_REDIRECTOR_ATTRPROVIDER_INVALID_NAME = unchecked((int)0x80245009), + + /// The value received from the attribute provider was invalid. + WU_E_REDIRECTOR_ATTRPROVIDER_INVALID_VALUE = unchecked((int)0x8024500A), + + /// There was an error in connecting to or parsing the response from the Service Locator Service redirector server. + WU_E_REDIRECTOR_SLS_GENERIC_ERROR = unchecked((int)0x8024500B), + + /// Connections to the redirector server are disallowed by managed policy. + WU_E_REDIRECTOR_CONNECT_POLICY = unchecked((int)0x8024500C), + + /// The redirector would go online but is disallowed by caller configuration. + WU_E_REDIRECTOR_ONLINE_DISALLOWED = unchecked((int)0x8024500D), + + /// The redirector failed for reasons not covered by another WU_E_REDIRECTOR_* error code. + WU_E_REDIRECTOR_UNEXPECTED = unchecked((int)0x802450FF), + + /// Verification of the servicing engine package failed. + WU_E_SIH_VERIFY_DOWNLOAD_ENGINE = unchecked((int)0x80245101), + + /// Verification of a servicing package failed. + WU_E_SIH_VERIFY_DOWNLOAD_PAYLOAD = unchecked((int)0x80245102), + + /// Verification of the staged engine failed. + WU_E_SIH_VERIFY_STAGE_ENGINE = unchecked((int)0x80245103), + + /// Verification of a staged payload failed. + WU_E_SIH_VERIFY_STAGE_PAYLOAD = unchecked((int)0x80245104), + + /// An internal error occurred where the servicing action was not found. + WU_E_SIH_ACTION_NOT_FOUND = unchecked((int)0x80245105), + + /// There was a parse error in the service environment response. + WU_E_SIH_SLS_PARSE = unchecked((int)0x80245106), + + /// A downloaded file failed an integrity check. + WU_E_SIH_INVALIDHASH = unchecked((int)0x80245107), + + /// No engine was provided by the server-initiated healing server response. + WU_E_SIH_NO_ENGINE = unchecked((int)0x80245108), + + /// Post-reboot install failed. + WU_E_SIH_POST_REBOOT_INSTALL_FAILED = unchecked((int)0x80245109), + + /// There were pending reboot actions, but cached SLS response was not found post-reboot. + WU_E_SIH_POST_REBOOT_NO_CACHED_SLS_RESPONSE = unchecked((int)0x8024510A), + + /// Parsing command line arguments failed. + WU_E_SIH_PARSE = unchecked((int)0x8024510B), + + /// Security check failed. + WU_E_SIH_SECURITY = unchecked((int)0x8024510C), + + /// PPL check failed. + WU_E_SIH_PPL = unchecked((int)0x8024510D), + + /// Execution was disabled by policy. + WU_E_SIH_POLICY = unchecked((int)0x8024510E), + + /// A standard exception was caught. + WU_E_SIH_STDEXCEPTION = unchecked((int)0x8024510F), + + /// A non-standard exception was caught. + WU_E_SIH_NONSTDEXCEPTION = unchecked((int)0x80245110), + + /// The server-initiated healing engine encountered an exception not covered by another WU_E_SIH_* error code. + WU_E_SIH_ENGINE_EXCEPTION = unchecked((int)0x80245111), + + /// You are running SIH Client with cmd not supported on your platform. + WU_E_SIH_BLOCKED_FOR_PLATFORM = unchecked((int)0x80245112), + + /// Another SIH Client is already running. + WU_E_SIH_ANOTHER_INSTANCE_RUNNING = unchecked((int)0x80245113), + + /// Disable DNS resiliency feature per service configuration. + WU_E_SIH_DNSRESILIENCY_OFF = unchecked((int)0x80245114), + + /// There was a failure for reasons not covered by another WU_E_SIH_* error code. + WU_E_SIH_UNEXPECTED = unchecked((int)0x802451FF), + + /// A driver was skipped. + WU_E_DRV_PRUNED = unchecked((int)0x8024C001), + + /// A property for the driver could not be found. It may not conform with required specifications. + WU_E_DRV_NOPROP_OR_LEGACY = unchecked((int)0x8024C002), + + /// The registry type read for the driver does not match the expected type. + WU_E_DRV_REG_MISMATCH = unchecked((int)0x8024C003), + + /// The driver update is missing metadata. + WU_E_DRV_NO_METADATA = unchecked((int)0x8024C004), + + /// The driver update is missing a required attribute. + WU_E_DRV_MISSING_ATTRIBUTE = unchecked((int)0x8024C005), + + /// Driver synchronization failed. + WU_E_DRV_SYNC_FAILED = unchecked((int)0x8024C006), + + /// Information required for the synchronization of applicable printers is missing. + WU_E_DRV_NO_PRINTER_CONTENT = unchecked((int)0x8024C007), + + /// After installing a driver update, the updated device has reported a problem. + WU_E_DRV_DEVICE_PROBLEM = unchecked((int)0x8024C008), + + /// A driver error not covered by another WU_E_DRV_* code. + WU_E_DRV_UNEXPECTED = unchecked((int)0x8024CFFF), + + /// An operation failed because Windows Update Agent is shutting down. + WU_E_DS_SHUTDOWN = unchecked((int)0x80248000), + + /// An operation failed because the data store was in use. + WU_E_DS_INUSE = unchecked((int)0x80248001), + + /// The current and expected states of the data store do not match. + WU_E_DS_INVALID = unchecked((int)0x80248002), + + /// The data store is missing a table. + WU_E_DS_TABLEMISSING = unchecked((int)0x80248003), + + /// The data store contains a table with unexpected columns. + WU_E_DS_TABLEINCORRECT = unchecked((int)0x80248004), + + /// A table could not be opened because the table is not in the data store. + WU_E_DS_INVALIDTABLENAME = unchecked((int)0x80248005), + + /// The current and expected versions of the data store do not match. + WU_E_DS_BADVERSION = unchecked((int)0x80248006), + + /// The information requested is not in the data store. + WU_E_DS_NODATA = unchecked((int)0x80248007), + + /// The data store is missing required information or has a NULL in a table column that requires a non-null value. + WU_E_DS_MISSINGDATA = unchecked((int)0x80248008), + + /// The data store is missing required information or has a reference to missing license terms, file, localized property or linked row. + WU_E_DS_MISSINGREF = unchecked((int)0x80248009), + + /// The update was not processed because its update handler could not be recognized. + WU_E_DS_UNKNOWNHANDLER = unchecked((int)0x8024800A), + + /// The update was not deleted because it is still referenced by one or more services. + WU_E_DS_CANTDELETE = unchecked((int)0x8024800B), + + /// The data store section could not be locked within the allotted time. + WU_E_DS_LOCKTIMEOUTEXPIRED = unchecked((int)0x8024800C), + + /// The category was not added because it contains no parent categories and is not a top-level category itself. + WU_E_DS_NOCATEGORIES = unchecked((int)0x8024800D), + + /// The row was not added because an existing row has the same primary key. + WU_E_DS_ROWEXISTS = unchecked((int)0x8024800E), + + /// The data store could not be initialized because it was locked by another process. + WU_E_DS_STOREFILELOCKED = unchecked((int)0x8024800F), + + /// The data store is not allowed to be registered with COM in the current process. + WU_E_DS_CANNOTREGISTER = unchecked((int)0x80248010), + + /// Could not create a data store object in another process. + WU_E_DS_UNABLETOSTART = unchecked((int)0x80248011), + + /// The server sent the same update to the client with two different revision IDs. + WU_E_DS_DUPLICATEUPDATEID = unchecked((int)0x80248013), + + /// An operation did not complete because the service is not in the data store. + WU_E_DS_UNKNOWNSERVICE = unchecked((int)0x80248014), + + /// An operation did not complete because the registration of the service has expired. + WU_E_DS_SERVICEEXPIRED = unchecked((int)0x80248015), + + /// A request to hide an update was declined because it is a mandatory update or because it was deployed with a deadline. + WU_E_DS_DECLINENOTALLOWED = unchecked((int)0x80248016), + + /// A table was not closed because it is not associated with the session. + WU_E_DS_TABLESESSIONMISMATCH = unchecked((int)0x80248017), + + /// A table was not closed because it is not associated with the session. + WU_E_DS_SESSIONLOCKMISMATCH = unchecked((int)0x80248018), + + /// A request to remove the Windows Update service or to unregister it with Automatic Updates was declined because it is a built-in service and/or Automatic Updates cannot fall back to another service. + WU_E_DS_NEEDWINDOWSSERVICE = unchecked((int)0x80248019), + + /// A request was declined because the operation is not allowed. + WU_E_DS_INVALIDOPERATION = unchecked((int)0x8024801A), + + /// The schema of the current data store and the schema of a table in a backup XML document do not match. + WU_E_DS_SCHEMAMISMATCH = unchecked((int)0x8024801B), + + /// The data store requires a session reset; release the session and retry with a new session. + WU_E_DS_RESETREQUIRED = unchecked((int)0x8024801C), + + /// A data store operation did not complete because it was requested with an impersonated identity. + WU_E_DS_IMPERSONATED = unchecked((int)0x8024801D), + + /// An operation against update metadata did not complete because the data was never received from server. + WU_E_DS_DATANOTAVAILABLE = unchecked((int)0x8024801E), + + /// An operation against update metadata did not complete because the data was available but not loaded from datastore. + WU_E_DS_DATANOTLOADED = unchecked((int)0x8024801F), + + /// A data store operation did not complete because no such update revision is known. + WU_E_DS_NODATA_NOSUCHREVISION = unchecked((int)0x80248020), + + /// A data store operation did not complete because no such update is known. + WU_E_DS_NODATA_NOSUCHUPDATE = unchecked((int)0x80248021), + + /// A data store operation did not complete because an update's EULA information is missing. + WU_E_DS_NODATA_EULA = unchecked((int)0x80248022), + + /// A data store operation did not complete because a service's information is missing. + WU_E_DS_NODATA_SERVICE = unchecked((int)0x80248023), + + /// A data store operation did not complete because a service's synchronization information is missing. + WU_E_DS_NODATA_COOKIE = unchecked((int)0x80248024), + + /// A data store operation did not complete because a timer's information is missing. + WU_E_DS_NODATA_TIMER = unchecked((int)0x80248025), + + /// A data store operation did not complete because a download's information is missing. + WU_E_DS_NODATA_CCR = unchecked((int)0x80248026), + + /// A data store operation did not complete because a file's information is missing. + WU_E_DS_NODATA_FILE = unchecked((int)0x80248027), + + /// A data store operation did not complete because a download job's information is missing. + WU_E_DS_NODATA_DOWNLOADJOB = unchecked((int)0x80248028), + + /// A data store operation did not complete because a service's timestamp information is missing. + WU_E_DS_NODATA_TMI = unchecked((int)0x80248029), + + /// A data store error not covered by another WU_E_DS_* code. + WU_E_DS_UNEXPECTED = unchecked((int)0x80248FFF), + + /// Parsing of the rule file failed. + WU_E_INVENTORY_PARSEFAILED = unchecked((int)0x80249001), + + /// Failed to get the requested inventory type from the server. + WU_E_INVENTORY_GET_INVENTORY_TYPE_FAILED = unchecked((int)0x80249002), + + /// Failed to upload inventory result to the server. + WU_E_INVENTORY_RESULT_UPLOAD_FAILED = unchecked((int)0x80249003), + + /// There was an inventory error not covered by another error code. + WU_E_INVENTORY_UNEXPECTED = unchecked((int)0x80249004), + + /// A WMI error occurred when enumerating the instances for a particular class. + WU_E_INVENTORY_WMI_ERROR = unchecked((int)0x80249005), + + /// Automatic Updates was unable to service incoming requests. + WU_E_AU_NOSERVICE = unchecked((int)0x8024A000), + + /// The old version of the Automatic Updates client has stopped because the WSUS server has been upgraded. + WU_E_AU_NONLEGACYSERVER = unchecked((int)0x8024A002), + + /// The old version of the Automatic Updates client was disabled. + WU_E_AU_LEGACYCLIENTDISABLED = unchecked((int)0x8024A003), + + /// Automatic Updates was unable to process incoming requests because it was paused. + WU_E_AU_PAUSED = unchecked((int)0x8024A004), + + /// No unmanaged service is registered with AU. + WU_E_AU_NO_REGISTERED_SERVICE = unchecked((int)0x8024A005), + + /// The default service registered with AU changed during the search. + WU_E_AU_DETECT_SVCID_MISMATCH = unchecked((int)0x8024A006), + + /// A reboot is in progress. + WU_E_REBOOT_IN_PROGRESS = unchecked((int)0x8024A007), + + /// Automatic Updates can't process incoming requests while Windows Welcome is running. + WU_E_AU_OOBE_IN_PROGRESS = unchecked((int)0x8024A008), + + /// An Automatic Updates error not covered by another WU_E_AU * code. + WU_E_AU_UNEXPECTED = unchecked((int)0x8024AFFF), + + /// A request for a remote update handler could not be completed because no remote process is available. + WU_E_UH_REMOTEUNAVAILABLE = unchecked((int)0x80242000), + + /// A request for a remote update handler could not be completed because the handler is local only. + WU_E_UH_LOCALONLY = unchecked((int)0x80242001), + + /// A request for an update handler could not be completed because the handler could not be recognized. + WU_E_UH_UNKNOWNHANDLER = unchecked((int)0x80242002), + + /// A remote update handler could not be created because one already exists. + WU_E_UH_REMOTEALREADYACTIVE = unchecked((int)0x80242003), + + /// A request for the handler to install (uninstall) an update could not be completed because the update does not support install (uninstall). + WU_E_UH_DOESNOTSUPPORTACTION = unchecked((int)0x80242004), + + /// An operation did not complete because the wrong handler was specified. + WU_E_UH_WRONGHANDLER = unchecked((int)0x80242005), + + /// A handler operation could not be completed because the update contains invalid metadata. + WU_E_UH_INVALIDMETADATA = unchecked((int)0x80242006), + + /// An operation could not be completed because the installer exceeded the time limit. + WU_E_UH_INSTALLERHUNG = unchecked((int)0x80242007), + + /// An operation being done by the update handler was cancelled. + WU_E_UH_OPERATIONCANCELLED = unchecked((int)0x80242008), + + /// An operation could not be completed because the handler-specific metadata is invalid. + WU_E_UH_BADHANDLERXML = unchecked((int)0x80242009), + + /// A request to the handler to install an update could not be completed because the update requires user input. + WU_E_UH_CANREQUIREINPUT = unchecked((int)0x8024200A), + + /// The installer failed to install (uninstall) one or more updates. + WU_E_UH_INSTALLERFAILURE = unchecked((int)0x8024200B), + + /// The update handler should download self-contained content rather than delta-compressed content for the update. + WU_E_UH_FALLBACKTOSELFCONTAINED = unchecked((int)0x8024200C), + + /// The update handler did not install the update because it needs to be downloaded again. + WU_E_UH_NEEDANOTHERDOWNLOAD = unchecked((int)0x8024200D), + + /// The update handler failed to send notification of the status of the install (uninstall) operation. + WU_E_UH_NOTIFYFAILURE = unchecked((int)0x8024200E), + + /// The file names contained in the update metadata and in the update package are inconsistent. + WU_E_UH_INCONSISTENT_FILE_NAMES = unchecked((int)0x8024200F), + + /// The update handler failed to fall back to the self-contained content. + WU_E_UH_FALLBACKERROR = unchecked((int)0x80242010), + + /// The update handler has exceeded the maximum number of download requests. + WU_E_UH_TOOMANYDOWNLOADREQUESTS = unchecked((int)0x80242011), + + /// The update handler has received an unexpected response from CBS. + WU_E_UH_UNEXPECTEDCBSRESPONSE = unchecked((int)0x80242012), + + /// The update metadata contains an invalid CBS package identifier. + WU_E_UH_BADCBSPACKAGEID = unchecked((int)0x80242013), + + /// The post-reboot operation for the update is still in progress. + WU_E_UH_POSTREBOOTSTILLPENDING = unchecked((int)0x80242014), + + /// The result of the post-reboot operation for the update could not be determined. + WU_E_UH_POSTREBOOTRESULTUNKNOWN = unchecked((int)0x80242015), + + /// The state of the update after its post-reboot operation has completed is unexpected. + WU_E_UH_POSTREBOOTUNEXPECTEDSTATE = unchecked((int)0x80242016), + + /// The OS servicing stack must be updated before this update is downloaded or installed. + WU_E_UH_NEW_SERVICING_STACK_REQUIRED = unchecked((int)0x80242017), + + /// A callback installer called back with an error. + WU_E_UH_CALLED_BACK_FAILURE = unchecked((int)0x80242018), + + /// The custom installer signature did not match the signature required by the update. + WU_E_UH_CUSTOMINSTALLER_INVALID_SIGNATURE = unchecked((int)0x80242019), + + /// The installer does not support the installation configuration. + WU_E_UH_UNSUPPORTED_INSTALLCONTEXT = unchecked((int)0x8024201A), + + /// The targeted session for install is invalid. + WU_E_UH_INVALID_TARGETSESSION = unchecked((int)0x8024201B), + + /// The handler failed to decrypt the update files. + WU_E_UH_DECRYPTFAILURE = unchecked((int)0x8024201C), + + /// The update handler is disabled until the system reboots. + WU_E_UH_HANDLER_DISABLEDUNTILREBOOT = unchecked((int)0x8024201D), + + /// The AppX infrastructure is not present on the system. + WU_E_UH_APPX_NOT_PRESENT = unchecked((int)0x8024201E), + + /// The update cannot be committed because it has not been previously installed or staged. + WU_E_UH_NOTREADYTOCOMMIT = unchecked((int)0x8024201F), + + /// The specified volume is not a valid AppX package volume. + WU_E_UH_APPX_INVALID_PACKAGE_VOLUME = unchecked((int)0x80242020), + + /// The configured default storage volume is unavailable. + WU_E_UH_APPX_DEFAULT_PACKAGE_VOLUME_UNAVAILABLE = unchecked((int)0x80242021), + + /// The volume on which the application is installed is unavailable. + WU_E_UH_APPX_INSTALLED_PACKAGE_VOLUME_UNAVAILABLE = unchecked((int)0x80242022), + + /// The specified package family is not present on the system. + WU_E_UH_APPX_PACKAGE_FAMILY_NOT_FOUND = unchecked((int)0x80242023), + + /// Unable to find a package volume marked as system. + WU_E_UH_APPX_SYSTEM_VOLUME_NOT_FOUND = unchecked((int)0x80242024), + + /// An update handler error not covered by another WU_E_UH_* code. + WU_E_UH_UNEXPECTED = unchecked((int)0x80242FFF), + + /// A download manager operation could not be completed because the requested file does not have a URL. + WU_E_DM_URLNOTAVAILABLE = unchecked((int)0x80246001), + + /// A download manager operation could not be completed because the file digest was not recognized. + WU_E_DM_INCORRECTFILEHASH = unchecked((int)0x80246002), + + /// A download manager operation could not be completed because the file metadata requested an unrecognized hash algorithm. + WU_E_DM_UNKNOWNALGORITHM = unchecked((int)0x80246003), + + /// An operation could not be completed because a download request is required from the download handler. + WU_E_DM_NEEDDOWNLOADREQUEST = unchecked((int)0x80246004), + + /// A download manager operation could not be completed because the network connection was unavailable. + WU_E_DM_NONETWORK = unchecked((int)0x80246005), + + /// A download manager operation could not be completed because the version of Background Intelligent Transfer Service (BITS) is incompatible. + WU_E_DM_WRONGBITSVERSION = unchecked((int)0x80246006), + + /// The update has not been downloaded. + WU_E_DM_NOTDOWNLOADED = unchecked((int)0x80246007), + + /// A download manager operation failed because the download manager was unable to connect the Background Intelligent Transfer Service (BITS). + WU_E_DM_FAILTOCONNECTTOBITS = unchecked((int)0x80246008), + + /// A download manager operation failed because there was an unspecified Background Intelligent Transfer Service (BITS) transfer error. + WU_E_DM_BITSTRANSFERERROR = unchecked((int)0x80246009), + + /// A download must be restarted because the location of the source of the download has changed. + WU_E_DM_DOWNLOADLOCATIONCHANGED = unchecked((int)0x8024600A), + + /// A download must be restarted because the update content changed in a new revision. + WU_E_DM_CONTENTCHANGED = unchecked((int)0x8024600B), + + /// A download failed because the current network limits downloads by update size for the update service. + WU_E_DM_DOWNLOADLIMITEDBYUPDATESIZE = unchecked((int)0x8024600C), + + /// The download failed because the client was denied authorization to download the content. + WU_E_DM_UNAUTHORIZED = unchecked((int)0x8024600E), + + /// The download failed because the user token associated with the BITS job no longer exists. + WU_E_DM_BG_ERROR_TOKEN_REQUIRED = unchecked((int)0x8024600F), + + /// The sandbox directory for the downloaded update was not found. + WU_E_DM_DOWNLOADSANDBOXNOTFOUND = unchecked((int)0x80246010), + + /// The downloaded update has an unknown file path. + WU_E_DM_DOWNLOADFILEPATHUNKNOWN = unchecked((int)0x80246011), + + /// One or more of the files for the downloaded update is missing. + WU_E_DM_DOWNLOADFILEMISSING = unchecked((int)0x80246012), + + /// An attempt was made to access a downloaded update that has already been removed. + WU_E_DM_UPDATEREMOVED = unchecked((int)0x80246013), + + /// Windows Update couldn't find a needed portion of a downloaded update's file. + WU_E_DM_READRANGEFAILED = unchecked((int)0x80246014), + + /// The download failed because the client was denied authorization to download the content due to no user logged on. + WU_E_DM_UNAUTHORIZED_NO_USER = unchecked((int)0x80246016), + + /// The download failed because the local user was denied authorization to download the content. + WU_E_DM_UNAUTHORIZED_LOCAL_USER = unchecked((int)0x80246017), + + /// The download failed because the domain user was denied authorization to download the content. + WU_E_DM_UNAUTHORIZED_DOMAIN_USER = unchecked((int)0x80246018), + + /// The download failed because the MSA account associated with the user was denied authorization to download the content. + WU_E_DM_UNAUTHORIZED_MSA_USER = unchecked((int)0x80246019), + + /// The download will be continued by falling back to BITS to download the content. + WU_E_DM_FALLINGBACKTOBITS = unchecked((int)0x8024601A), + + /// Another caller has requested download to a different volume. + WU_E_DM_DOWNLOAD_VOLUME_CONFLICT = unchecked((int)0x8024601B), + + /// The hash of the update's sandbox does not match the expected value. + WU_E_DM_SANDBOX_HASH_MISMATCH = unchecked((int)0x8024601C), + + /// The hard reserve id specified conflicts with an id from another caller. + WU_E_DM_HARDRESERVEID_CONFLICT = unchecked((int)0x8024601D), + + /// The update has to be downloaded via DO. + WU_E_DM_DOSVC_REQUIRED = unchecked((int)0x8024601E), + + /// There was a download manager error not covered by another WU_E_DM_* error code. + WU_E_DM_UNEXPECTED = unchecked((int)0x80246FFF), + + /// Windows Update Agent could not be updated because an INF file contains invalid information. + WU_E_SETUP_INVALID_INFDATA = unchecked((int)0x8024D001), + + /// Windows Update Agent could not be updated because the wuident.cab file contains invalid information. + WU_E_SETUP_INVALID_IDENTDATA = unchecked((int)0x8024D002), + + /// Windows Update Agent could not be updated because of an internal error that caused setup initialization to be performed twice. + WU_E_SETUP_ALREADY_INITIALIZED = unchecked((int)0x8024D003), + + /// Windows Update Agent could not be updated because setup initialization never completed successfully. + WU_E_SETUP_NOT_INITIALIZED = unchecked((int)0x8024D004), + + /// Windows Update Agent could not be updated because the versions specified in the INF do not match the actual source file versions. + WU_E_SETUP_SOURCE_VERSION_MISMATCH = unchecked((int)0x8024D005), + + /// Windows Update Agent could not be updated because a WUA file on the target system is newer than the corresponding source file. + WU_E_SETUP_TARGET_VERSION_GREATER = unchecked((int)0x8024D006), + + /// Windows Update Agent could not be updated because regsvr32.exe returned an error. + WU_E_SETUP_REGISTRATION_FAILED = unchecked((int)0x8024D007), + + /// An update to the Windows Update Agent was skipped because previous attempts to update have failed. + WU_E_SELFUPDATE_SKIP_ON_FAILURE = unchecked((int)0x8024D008), + + /// An update to the Windows Update Agent was skipped due to a directive in the wuident.cab file. + WU_E_SETUP_SKIP_UPDATE = unchecked((int)0x8024D009), + + /// Windows Update Agent could not be updated because the current system configuration is not supported. + WU_E_SETUP_UNSUPPORTED_CONFIGURATION = unchecked((int)0x8024D00A), + + /// Windows Update Agent could not be updated because the system is configured to block the update. + WU_E_SETUP_BLOCKED_CONFIGURATION = unchecked((int)0x8024D00B), + + /// Windows Update Agent could not be updated because a restart of the system is required. + WU_E_SETUP_REBOOT_TO_FIX = unchecked((int)0x8024D00C), + + /// Windows Update Agent setup is already running. + WU_E_SETUP_ALREADYRUNNING = unchecked((int)0x8024D00D), + + /// Windows Update Agent setup package requires a reboot to complete installation. + WU_E_SETUP_REBOOTREQUIRED = unchecked((int)0x8024D00E), + + /// Windows Update Agent could not be updated because the setup handler failed during execution. + WU_E_SETUP_HANDLER_EXEC_FAILURE = unchecked((int)0x8024D00F), + + /// Windows Update Agent could not be updated because the registry contains invalid information. + WU_E_SETUP_INVALID_REGISTRY_DATA = unchecked((int)0x8024D010), + + /// Windows Update Agent must be updated before search can continue. + WU_E_SELFUPDATE_REQUIRED = unchecked((int)0x8024D011), + + /// Windows Update Agent must be updated before search can continue. An administrator is required to perform the operation. + WU_E_SELFUPDATE_REQUIRED_ADMIN = unchecked((int)0x8024D012), + + /// Windows Update Agent could not be updated because the server does not contain update information for this version. + WU_E_SETUP_WRONG_SERVER_VERSION = unchecked((int)0x8024D013), + + /// Windows Update Agent is successfully updated, but a reboot is required to complete the setup. + WU_E_SETUP_DEFERRABLE_REBOOT_PENDING = unchecked((int)0x8024D014), + + /// Windows Update Agent is successfully updated, but a reboot is required to complete the setup. + WU_E_SETUP_NON_DEFERRABLE_REBOOT_PENDING = unchecked((int)0x8024D015), + + /// Windows Update Agent could not be updated because of an unknown error. + WU_E_SETUP_FAIL = unchecked((int)0x8024D016), + + /// Windows Update Agent could not be updated because of an error not covered by another WU_E_SETUP_* error code. + WU_E_SETUP_UNEXPECTED = unchecked((int)0x8024DFFF), + + /// An expression evaluator operation could not be completed because an expression was unrecognized. + WU_E_EE_UNKNOWN_EXPRESSION = unchecked((int)0x8024E001), + + /// An expression evaluator operation could not be completed because an expression was invalid. + WU_E_EE_INVALID_EXPRESSION = unchecked((int)0x8024E002), + + /// An expression evaluator operation could not be completed because an expression contains an incorrect number of metadata nodes. + WU_E_EE_MISSING_METADATA = unchecked((int)0x8024E003), + + /// An expression evaluator operation could not be completed because the version of the serialized expression data is invalid. + WU_E_EE_INVALID_VERSION = unchecked((int)0x8024E004), + + /// The expression evaluator could not be initialized. + WU_E_EE_NOT_INITIALIZED = unchecked((int)0x8024E005), + + /// An expression evaluator operation could not be completed because there was an invalid attribute. + WU_E_EE_INVALID_ATTRIBUTEDATA = unchecked((int)0x8024E006), + + /// An expression evaluator operation could not be completed because the cluster state of the computer could not be determined. + WU_E_EE_CLUSTER_ERROR = unchecked((int)0x8024E007), + + /// There was an expression evaluator error not covered by another WU_E_EE_* error code. + WU_E_EE_UNEXPECTED = unchecked((int)0x8024EFFF), + + /// The results of download and installation could not be read from the registry due to an unrecognized data format version. + WU_E_INSTALLATION_RESULTS_UNKNOWN_VERSION = unchecked((int)0x80243001), + + /// The results of download and installation could not be read from the registry due to an invalid data format. + WU_E_INSTALLATION_RESULTS_INVALID_DATA = unchecked((int)0x80243002), + + /// The results of download and installation are not available; the operation may have failed to start. + WU_E_INSTALLATION_RESULTS_NOT_FOUND = unchecked((int)0x80243003), + + /// A failure occurred when trying to create an icon in the taskbar notification area. + WU_E_TRAYICON_FAILURE = unchecked((int)0x80243004), + + /// Unable to show UI when in non-UI mode; WU client UI modules may not be installed. + WU_E_NON_UI_MODE = unchecked((int)0x80243FFD), + + /// Unsupported version of WU client UI exported functions. + WU_E_WUCLTUI_UNSUPPORTED_VERSION = unchecked((int)0x80243FFE), + + /// There was a user interface error not covered by another WU_E_AUCLIENT_* error code. + WU_E_AUCLIENT_UNEXPECTED = unchecked((int)0x80243FFF), + + /// The event cache file was defective. + WU_E_REPORTER_EVENTCACHECORRUPT = unchecked((int)0x8024F001), + + /// The XML in the event namespace descriptor could not be parsed. + WU_E_REPORTER_EVENTNAMESPACEPARSEFAILED = unchecked((int)0x8024F002), + + /// The XML in the event namespace descriptor could not be parsed. + WU_E_INVALID_EVENT = unchecked((int)0x8024F003), + + /// The server rejected an event because the server was too busy. + WU_E_SERVER_BUSY = unchecked((int)0x8024F004), + + /// The specified callback cookie is not found. + WU_E_CALLBACK_COOKIE_NOT_FOUND = unchecked((int)0x8024F005), + + /// There was a reporter error not covered by another error code. + WU_E_REPORTER_UNEXPECTED = unchecked((int)0x8024FFFF), + + /// An operation could not be completed because the scan package was invalid. + WU_E_OL_INVALID_SCANFILE = unchecked((int)0x80247001), + + /// An operation could not be completed because the scan package requires a greater version of the Windows Update Agent. + WU_E_OL_NEWCLIENT_REQUIRED = unchecked((int)0x80247002), + + /// An invalid event payload was specified. + WU_E_INVALID_EVENT_PAYLOAD = unchecked((int)0x80247003), + + /// The size of the event payload submitted is invalid. + WU_E_INVALID_EVENT_PAYLOADSIZE = unchecked((int)0x80247004), + + /// The service is not registered. + WU_E_SERVICE_NOT_REGISTERED = unchecked((int)0x80247005), + + /// Search using the scan package failed. + WU_E_OL_UNEXPECTED = unchecked((int)0x80247FFF), + + /// No operation was required by update metadata verification. + WU_E_METADATA_NOOP = unchecked((int)0x80247100), + + /// The binary encoding of metadata config data was invalid. + WU_E_METADATA_CONFIG_INVALID_BINARY_ENCODING = unchecked((int)0x80247101), + + /// Unable to fetch required configuration for metadata signature verification. + WU_E_METADATA_FETCH_CONFIG = unchecked((int)0x80247102), + + /// A metadata verification operation failed due to an invalid parameter. + WU_E_METADATA_INVALID_PARAMETER = unchecked((int)0x80247104), + + /// A metadata verification operation failed due to reasons not covered by another error code. + WU_E_METADATA_UNEXPECTED = unchecked((int)0x80247105), + + /// None of the update metadata had verification data, which may be disabled on the update server. + WU_E_METADATA_NO_VERIFICATION_DATA = unchecked((int)0x80247106), + + /// The fragment signing configuration used for verifying update metadata signatures was bad. + WU_E_METADATA_BAD_FRAGMENTSIGNING_CONFIG = unchecked((int)0x80247107), + + /// There was an unexpected operational failure while parsing fragment signing configuration. + WU_E_METADATA_FAILURE_PROCESSING_FRAGMENTSIGNING_CONFIG = unchecked((int)0x80247108), + + /// Required xml data was missing from configuration. + WU_E_METADATA_XML_MISSING = unchecked((int)0x80247120), + + /// Required fragmentsigning data was missing from xml configuration. + WU_E_METADATA_XML_FRAGMENTSIGNING_MISSING = unchecked((int)0x80247121), + + /// Required mode data was missing from xml configuration. + WU_E_METADATA_XML_MODE_MISSING = unchecked((int)0x80247122), + + /// An invalid metadata enforcement mode was detected. + WU_E_METADATA_XML_MODE_INVALID = unchecked((int)0x80247123), + + /// An invalid timestamp validity window configuration was detected. + WU_E_METADATA_XML_VALIDITY_INVALID = unchecked((int)0x80247124), + + /// Required leaf certificate data was missing from xml configuration. + WU_E_METADATA_XML_LEAFCERT_MISSING = unchecked((int)0x80247125), + + /// Required intermediate certificate data was missing from xml configuration. + WU_E_METADATA_XML_INTERMEDIATECERT_MISSING = unchecked((int)0x80247126), + + /// Required leaf certificate id attribute was missing from xml configuration. + WU_E_METADATA_XML_LEAFCERT_ID_MISSING = unchecked((int)0x80247127), + + /// Required certificate base64CerData attribute was missing from xml configuration. + WU_E_METADATA_XML_BASE64CERDATA_MISSING = unchecked((int)0x80247128), + + /// The metadata for an update was found to have a bad or invalid digital signature. + WU_E_METADATA_BAD_SIGNATURE = unchecked((int)0x80247140), + + /// An unsupported hash algorithm for metadata verification was specified. + WU_E_METADATA_UNSUPPORTED_HASH_ALG = unchecked((int)0x80247141), + + /// An error occurred during an update's metadata signature verification. + WU_E_METADATA_SIGNATURE_VERIFY_FAILED = unchecked((int)0x80247142), + + /// An failure occurred while verifying trust for metadata signing certificate chains. + WU_E_METADATATRUST_CERTIFICATECHAIN_VERIFICATION = unchecked((int)0x80247150), + + /// A metadata signing certificate had an untrusted certificate chain. + WU_E_METADATATRUST_UNTRUSTED_CERTIFICATECHAIN = unchecked((int)0x80247151), + + /// An expected metadata timestamp token was missing. + WU_E_METADATA_TIMESTAMP_TOKEN_MISSING = unchecked((int)0x80247160), + + /// A metadata Timestamp token failed verification. + WU_E_METADATA_TIMESTAMP_TOKEN_VERIFICATION_FAILED = unchecked((int)0x80247161), + + /// A metadata timestamp token signer certificate chain was untrusted. + WU_E_METADATA_TIMESTAMP_TOKEN_UNTRUSTED = unchecked((int)0x80247162), + + /// A metadata signature timestamp token was no longer within the validity window. + WU_E_METADATA_TIMESTAMP_TOKEN_VALIDITY_WINDOW = unchecked((int)0x80247163), + + /// A metadata timestamp token failed signature validation + WU_E_METADATA_TIMESTAMP_TOKEN_SIGNATURE = unchecked((int)0x80247164), + + /// A metadata timestamp token certificate failed certificate chain verification. + WU_E_METADATA_TIMESTAMP_TOKEN_CERTCHAIN = unchecked((int)0x80247165), + + /// A failure occurred when refreshing a missing timestamp token from the network. + WU_E_METADATA_TIMESTAMP_TOKEN_REFRESHONLINE = unchecked((int)0x80247166), + + /// All update metadata verification timestamp tokens from the timestamp token cache are invalid. + WU_E_METADATA_TIMESTAMP_TOKEN_ALL_BAD = unchecked((int)0x80247167), + + /// No update metadata verification timestamp tokens exist in the timestamp token cache. + WU_E_METADATA_TIMESTAMP_TOKEN_NODATA = unchecked((int)0x80247168), + + /// An error occurred during cache lookup of update metadata verification timestamp token. + WU_E_METADATA_TIMESTAMP_TOKEN_CACHELOOKUP = unchecked((int)0x80247169), + + /// An metadata timestamp token validity window failed unexpectedly due to reasons not covered by another error code. + WU_E_METADATA_TIMESTAMP_TOKEN_VALIDITYWINDOW_UNEXPECTED = unchecked((int)0x8024717E), + + /// An metadata timestamp token verification operation failed due to reasons not covered by another error code. + WU_E_METADATA_TIMESTAMP_TOKEN_UNEXPECTED = unchecked((int)0x8024717F), + + /// An expected metadata signing certificate was missing. + WU_E_METADATA_CERT_MISSING = unchecked((int)0x80247180), + + /// The transport encoding of a metadata signing leaf certificate was malformed. + WU_E_METADATA_LEAFCERT_BAD_TRANSPORT_ENCODING = unchecked((int)0x80247181), + + /// The transport encoding of a metadata signing intermediate certificate was malformed. + WU_E_METADATA_INTCERT_BAD_TRANSPORT_ENCODING = unchecked((int)0x80247182), + + /// A metadata certificate chain was untrusted. + WU_E_METADATA_CERT_UNTRUSTED = unchecked((int)0x80247183), + + /// The task is currently in progress. + WU_E_WUTASK_INPROGRESS = unchecked((int)0x8024B001), + + /// The operation cannot be completed since the task status is currently disabled. + WU_E_WUTASK_STATUS_DISABLED = unchecked((int)0x8024B002), + + /// The operation cannot be completed since the task is not yet started. + WU_E_WUTASK_NOT_STARTED = unchecked((int)0x8024B003), + + /// The task was stopped and needs to be run again to complete. + WU_E_WUTASK_RETRY = unchecked((int)0x8024B004), + + /// Cannot cancel a non-scheduled install. + WU_E_WUTASK_CANCELINSTALL_DISALLOWED = unchecked((int)0x8024B005), + + /// Hardware capability meta data was not found after a sync with the service. + WU_E_UNKNOWN_HARDWARECAPABILITY = unchecked((int)0x8024B101), + + /// Hardware capability meta data was malformed and/or failed to parse. + WU_E_BAD_XML_HARDWARECAPABILITY = unchecked((int)0x8024B102), + + /// Unable to complete action due to WMI dependency, which isn't supported on this platform. + WU_E_WMI_NOT_SUPPORTED = unchecked((int)0x8024B103), + + /// Merging of the update is not allowed + WU_E_UPDATE_MERGE_NOT_ALLOWED = unchecked((int)0x8024B104), + + /// Installing merged updates only. So skipping non mergeable updates. + WU_E_SKIPPED_UPDATE_INSTALLATION = unchecked((int)0x8024B105), + + /// SLS response returned invalid revision number. + WU_E_SLS_INVALID_REVISION = unchecked((int)0x8024B201), + + /// File signature validation fails to find valid RSA signature on infrastructure payload. + WU_E_FILETRUST_DUALSIGNATURE_RSA = unchecked((int)0x8024B301), + + /// File signature validation fails to find valid ECC signature on infrastructure payload. + WU_E_FILETRUST_DUALSIGNATURE_ECC = unchecked((int)0x8024B302), + + /// The subject is not trusted by WU for the specified action. + WU_E_TRUST_SUBJECT_NOT_TRUSTED = unchecked((int)0x8024B303), + + /// Unknown trust provider for WU. + WU_E_TRUST_PROVIDER_UNKNOWN = unchecked((int)0x8024B304), + } +} \ No newline at end of file diff --git a/UnitTests/PInvoke/WUApi/WUApi.csproj b/UnitTests/PInvoke/WUApi/WUApi.csproj index 1158815e..8636f0d2 100644 --- a/UnitTests/PInvoke/WUApi/WUApi.csproj +++ b/UnitTests/PInvoke/WUApi/WUApi.csproj @@ -3,6 +3,17 @@ UnitTest.PInvoke.WUApi - + + tlbimp + 0 + 2 + b596cc9f-56e5-419e-a622-e01bb457431e + 0 + false + true + + + + \ No newline at end of file diff --git a/UnitTests/PInvoke/WUApi/WUApiTests.cs b/UnitTests/PInvoke/WUApi/WUApiTests.cs index edf4fac5..413fdb96 100644 --- a/UnitTests/PInvoke/WUApi/WUApiTests.cs +++ b/UnitTests/PInvoke/WUApi/WUApiTests.cs @@ -1,65 +1,306 @@ -using NUnit.Framework; +//#define WUTYPELIB +using NUnit.Framework; using NUnit.Framework.Internal; -using System.Collections; +using System.Collections.Generic; using System.Linq; -using Vanara.Extensions.Reflection; +using System.Threading; +using System.Threading.Tasks; +#if !WUTYPELIB +using Vanara.WindowsUpdate; using static Vanara.PInvoke.WUApi; +#else +using WUApiLib; +#endif namespace Vanara.PInvoke.Tests; [TestFixture] public class WUApiTests { - private static readonly string[] UpdProps = [ "AutoSelectOnWebSites", "BundledUpdates", "CanRequireSource", "Categories", "Deadline", "DeltaCompressedContentAvailable", - "DeltaCompressedContentPreferred", "DeploymentAction", "Description", "DownloadContents", "DownloadPriority", "EulaAccepted", "EulaText", "HandlerID", - "Identity", "Image", "InstallationBehavior", "IsBeta", "IsDownloaded", "IsHidden", "IsInstalled", "IsMandatory", "IsUninstallable", "KBArticleIDs", - "Languages", "LastDeploymentChangeTime", "MaxDownloadSize", "MinDownloadSize", "MoreInfoUrls", "MsrcSeverity", "RecommendedCpuSpeed", - "RecommendedHardDiskSpace", "RecommendedMemory", "ReleaseNotes", "SecurityBulletinIDs", "SupersededUpdateIDs", "SupportUrl", "Title", "Type", - "UninstallationBehavior", "UninstallationNotes", "UninstallationSteps", "KBArticleIDs", "DeploymentAction", "DownloadPriority", "DownloadContents", - "RebootRequired", "IsPresent", "CveIDs", "BrowseOnly", "PerUser", "AutoSelection", "AutoDownload" ]; + [Test] + public void TestAgent() + { + WindowsUpdateAgentInfo agent = new(); + Version? pv = null, ver = null; +#if !WUTYPELIB + Assert.That(() => pv = agent.ProductVersion, Throws.Nothing); + Assert.That(() => ver = agent.ApiVersion, Throws.Nothing); +#endif + TestContext.WriteLine($"Version: {pv}, Api: {ver}"); + } + + [Test] + public void TestAuto() + { + AutomaticUpdates auto = new(); + auto.WriteValues(); + //auto.EnableService(); + auto.DetectNow(); + auto.Resume(); + //auto.ShowSettingsDialog(); + + //var t = auto.Settings.ScheduledInstallationTime; + //auto.Settings.ScheduledInstallationTime = t + 1; + //try { auto.Settings.Save(); Assert.That(auto.Settings.ScheduledInstallationTime, Is.EqualTo(t + 1)); } + //finally { auto.Settings.ScheduledInstallationTime = t; } + } + + [Test] + public void TestDownloader() + { + UpdateDownloader downloader = new(); + downloader.WriteValues(); + } + + [Test] + public void TestInstaller() + { + AutomaticUpdates auto = new(); + if (!auto.ServiceEnabled) + { + for (int i = 0; i <= 5 && !auto.ServiceEnabled; i++) + { + auto.EnableService(); + Thread.Sleep(2000); + } + Assert.That(auto.ServiceEnabled, Is.True); + } + + var autoUpd = new UpdateSearcher().Search("IsInstalled=0").Updates.Where(u => u.AutoSelectOnWebSites).ToList(); + var dnld = autoUpd.Where(u => !u.IsDownloaded).ToList(); + if (dnld.Count > 0) + new UpdateDownloader(dnld).DownloadAsync(p => p.WriteValues()).Result.WriteValues(); + + var res = new UpdateInstaller(autoUpd) { AllowSourcePrompts = false, ForceQuiet = true }.InstallAsync(p => p.WriteValues()).Result; + Assert.That(res.HResult, Is.EqualTo((HRESULT)0)); + res.WriteValues(); + } + + [Test] + public void TestSysInfo() + { + SystemInformation info = new(); + info.WriteValues(); + } + +#if !WUTYPELIB + [Test] + public void TestUpdateHistory() + { + foreach (UpdateHistoryEntry e in new UpdateHistory()) + { + TestContext.WriteLine(new string('=', 50)); + e.WriteValues(false); + } + } +#endif [Test] public void TestUpdateSearch() { - IUpdateSession2 sess = new(); - var searcher = sess.CreateUpdateSearcher(); - searcher.IncludePotentiallySupersededUpdates = true; - var res = searcher.Search("IsInstalled=0"); - foreach (var upd in res.Updates.Cast()) + UpdateSearcher searcher = new(); + var res = searcher.Search(""); + foreach (var upd in res.Updates) { TestContext.WriteLine(new string('=', 50)); - foreach (var prop in UpdProps) - { - try - { - var val = upd.GetPropertyValue(prop); - if (val is null) - continue; - if (val is not string and IEnumerable ie) - try { TestContext.WriteLine($"{prop}: {string.Join(',', ie.Cast().Select(o => o is string s ? s : o.GetPropertyValue("Name")))}"); } - catch { TestContext.WriteLine($"{prop}: {val.GetPropertyValue("Count")} objects"); } - else - TestContext.WriteLine($"{prop}: {val}"); - } - catch (COMException ce) - { - if (ce.ErrorCode == HRESULT.E_NOTIMPL) - continue; - throw; - } - } + TestContext.WriteLine(upd.Title); + //upd.WriteValues(false); } } +#if !WUTYPELIB + [Test] + public void TestFLuentUpdateSearch() + { + UpdateSearcher searcher = new(); + var res = searcher.Where.Not.Installed.And.Not.Hidden.Search(); + foreach (var upd in res.Updates) + { + TestContext.WriteLine(new string('=', 50)); + upd.WriteValues(false); + } + } +#endif + + [Test] + public async Task TestUpdateSearchAsync() + { + UpdateSearcher searcher = new(); + var res = await searcher.SearchAsync("IsInstalled=1"); + foreach (var upd in res.Updates) + { + TestContext.WriteLine(new string('=', 50)); + TestContext.WriteLine(upd.Title); + //upd.WriteValues(false); + } + } + + [Test] + public void TestSession() + { +#if WUTYPELIB + UpdateSession UpdateSession = new(); +#endif + TestContext.WriteLine($"ClientID: {UpdateSession.ClientApplicationID}, R/O: {UpdateSession.ReadOnly}, Locale: {UpdateSession.UserLocale}, "); + UpdateSession.ClientApplicationID = "Test"; + Assert.That(UpdateSession.ClientApplicationID, Is.EqualTo("Test")); + UpdateSession.UserLocale = (uint)LCID.LOCALE_INVARIANT; + Assert.That(UpdateSession.UserLocale, Is.EqualTo(LCID.LOCALE_INVARIANT)); + var wp = UpdateSession.WebProxy; + wp.WriteValues(false); + wp.UserName = "test"; + wp.BypassList.Add("168.0.0.1"); + UpdateSession.WebProxy = wp; + wp = UpdateSession.WebProxy; + Assert.That(wp.UserName, Is.EqualTo("test")); + Assert.That(wp.BypassList, Contains.Item("168.0.0.1")); + } + [Test] public void TestUpdateServiceManager() { - IUpdateServiceManager2 mgr = new() - { - ClientApplicationID = "Test" - }; - var svcid = Guid.NewGuid().ToString("D"); - mgr.AddService2(svcid, AddServiceFlag.asfRegisterServiceWithAU | AddServiceFlag.asfAllowPendingRegistration | AddServiceFlag.asfAllowOnlineRegistration, ""); + UpdateServiceManager mgr = new() { ClientApplicationID = "Test" }; + foreach (var up in mgr) + up.WriteValues(); + + var svcid = "7971f918-a847-4430-9279-4a52d1efe18d"; // Guid.NewGuid().ToString("D"); + var us = mgr.AddService(svcid, AddServiceFlag.asfAllowOnlineRegistration | AddServiceFlag.asfAllowPendingRegistration); + Assert.That(us?.ServiceID, Is.EqualTo(svcid)); + us?.WriteValues(); mgr.RemoveService(svcid); } -} \ No newline at end of file +} + +#if WUTYPELIB +internal static class Ext +{ + /*public static UpdateCollection ToCollection(this IEnumerable items) + { + if (items is UpdateCollection iuc) return iuc; + UpdateCollection c = new(); + foreach (var i in items) + c.Add(i); + return c; + }*/ + + public static Task InstallAsync(this IUpdateInstaller installer, Action progress, CancellationToken cancellationToken = default) + { + var task = new TaskCompletionSource(); + if (cancellationToken.IsCancellationRequested) + { + task.TrySetCanceled(cancellationToken); + return task.Task; + } + IInstallationJob? job = null; + CancellationTokenRegistration? reg = null; + job = installer.BeginInstall(new InstallationProgressChangeCallback(progress), new InstallationCompletedCallback(OnComplete), null); + reg = cancellationToken.Register(() => + { + task.TrySetCanceled(cancellationToken); + job?.RequestAbort(); + }); + return task.Task; + + void OnComplete(IInstallationJob _job2, IInstallationCompletedCallbackArgs _) + { + try + { + try { task.TrySetResult(installer.EndInstall(_job2)); } + catch (Exception e) { task.TrySetException(e); } + } + finally + { + job = null; + reg?.Dispose(); + } + } + } + + public static Task SearchAsync(this IUpdateSearcher searcher, string criteria, CancellationToken cancellationToken = default) + { + var task = new TaskCompletionSource(); + if (cancellationToken.IsCancellationRequested) + { + task.TrySetCanceled(cancellationToken); + return task.Task; + } + ISearchJob? job = null; + CancellationTokenRegistration? reg = null; + job = searcher.BeginSearch(criteria, new SearchCompletedCallback(OnComplete), null); + reg = cancellationToken.Register(() => + { + task.TrySetCanceled(cancellationToken); + job?.RequestAbort(); + }); + return task.Task; + + void OnComplete(ISearchJob _job, ISearchCompletedCallbackArgs _) + { + try + { + try { task.TrySetResult(searcher.EndSearch(_job)); } + catch (Exception e) { task.TrySetException(e); } + } + finally + { + job = null; + reg?.Dispose(); + } + } + } + + public static Task DownloadAsync(this IUpdateDownloader downloader, Action progress, CancellationToken cancellationToken = default(CancellationToken)) + { + var task = new TaskCompletionSource(); + if (cancellationToken.IsCancellationRequested) + { + task.TrySetCanceled(cancellationToken); + return task.Task; + } + IDownloadJob? job = null; + CancellationTokenRegistration? reg = null; + job = downloader.BeginDownload(new DownloadProgressChangedCallback(progress), new DownloadCompletedCallback(OnComplete), null); + reg = cancellationToken.Register(() => + { + task.TrySetCanceled(cancellationToken); + job?.RequestAbort(); + }); + return task.Task; + + void OnComplete(IDownloadJob _job, IDownloadCompletedCallbackArgs _) + { + try + { + try { task.TrySetResult(downloader.EndDownload(_job)); } + catch (Exception e) { task.TrySetException(e); } + } + finally + { + job = null; + reg?.Dispose(); + } + } + } + + internal class DownloadProgressChangedCallback(Action Action) : WUApiLib.IDownloadProgressChangedCallback + { + void WUApiLib.IDownloadProgressChangedCallback.Invoke(WUApiLib.IDownloadJob downloadJob, WUApiLib.IDownloadProgressChangedCallbackArgs callbackArgs) => Action?.Invoke(callbackArgs.Progress); + } + internal class DownloadCompletedCallback(Action Action) : WUApiLib.IDownloadCompletedCallback + { + void WUApiLib.IDownloadCompletedCallback.Invoke(WUApiLib.IDownloadJob downloadJob, WUApiLib.IDownloadCompletedCallbackArgs callbackArgs) => Action?.Invoke(downloadJob, callbackArgs); + } + internal class SearchCompletedCallback(Action Action) : WUApiLib.ISearchCompletedCallback + { + void WUApiLib.ISearchCompletedCallback.Invoke(WUApiLib.ISearchJob searchJob, WUApiLib.ISearchCompletedCallbackArgs callbackArgs) => Action?.Invoke(searchJob, callbackArgs); + } + internal class InstallationProgressChangeCallback(Action Action) : WUApiLib.IInstallationProgressChangedCallback + { + void WUApiLib.IInstallationProgressChangedCallback.Invoke(WUApiLib.IInstallationJob installationJob, WUApiLib.IInstallationProgressChangedCallbackArgs callbackArgs) => Action?.Invoke(callbackArgs.Progress); + } + internal class InstallationCompletedCallback(Action Action) : WUApiLib.IInstallationCompletedCallback + { + void WUApiLib.IInstallationCompletedCallback.Invoke(WUApiLib.IInstallationJob installationJob, WUApiLib.IInstallationCompletedCallbackArgs callbackArgs) => Action?.Invoke(installationJob, callbackArgs); + } +} +#endif \ No newline at end of file diff --git a/WindowsUpdate/Vanara.WindowsUpdate.csproj b/WindowsUpdate/Vanara.WindowsUpdate.csproj new file mode 100644 index 00000000..e2fa89cd --- /dev/null +++ b/WindowsUpdate/Vanara.WindowsUpdate.csproj @@ -0,0 +1,19 @@ + + + + WindowsUpdate.dll + + + PInvoke API (methods, structures and constants) imported from Windows WindowsUpdate.dll. + Vanara.PInvoke.WindowsUpdate + $(AssemblyName) + $(AssemblyName) + pinvoke;vanara;net-extensions;interop;WindowsUpdate + + + + + + + + \ No newline at end of file diff --git a/WindowsUpdate/WindowsUpdate.cs b/WindowsUpdate/WindowsUpdate.cs new file mode 100644 index 00000000..23d67aa5 --- /dev/null +++ b/WindowsUpdate/WindowsUpdate.cs @@ -0,0 +1,3090 @@ +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; +using Vanara.Collections; +using Vanara.PInvoke; +using static Vanara.PInvoke.WUApi; + +namespace Vanara.WindowsUpdate; + +/// +/// Represents a session in which the caller can perform operations that involve updates. For example, this object represents sessions in +/// which the caller performs a search, download, installation, or uninstallation operation. +/// +public static class UpdateSession +{ + [ThreadStatic] + private static readonly IUpdateSession sess = new(); + + /// Gets and sets the current client application. + /// Returns if the client application has not set the property. + public static string? ClientApplicationID { get => sess.ClientApplicationID; set => sess.ClientApplicationID = value; } + + /// Gets a that indicates whether the session object is read-only. + public static bool ReadOnly => sess.ReadOnly; + + /// + /// Gets and sets the preferred locale for which update information is retrieved.. + /// + /// If you do not specify the locale, the default is the user locale that GetUserDefaultUILanguage returns. If the information is not + /// available in a specified locale or in the user locale, Windows Update Agent (WUA) tries to retrieve the information from the default + /// update locale. + /// + /// + /// + /// + /// A search from an object that was created from the object fails if the + /// following conditions are true: + /// + /// + /// + /// A user or a power user set the UserLocale property for the UpdateSession instance to a locale. + /// + /// + /// The locale corresponds to a language that is not installed on the computer. + /// + /// + /// + public static LCID UserLocale + { + get => (sess as IUpdateSession2)?.UserLocale ?? LCID.LOCALE_SYSTEM_DEFAULT; + set { if (sess is IUpdateSession2 s2) s2.UserLocale = value; else throw new NotImplementedException(); } + } + + /// Gets and sets the proxy settings that are used to access the server. + public static WebProxy WebProxy { get => new(sess.WebProxy); set => sess.WebProxy = value.Interface; } + + /// Returns a UpdateDownloader instance for this session. + /// A UpdateDownloader instance for this session. + /// A UpdateDownloader instance can also be created by using the UpdateDownloader class. + public static UpdateDownloader CreateUpdateDownloader() => new(); + + /// Returns a UpdateInstaller instance for this session. + /// A UpdateInstaller instance for this session. + /// A UpdateInstaller instance can also be created by using the UpdateInstaller class. + public static UpdateInstaller CreateUpdateInstaller() => new(); + + /// Returns a UpdateSearcher instance for this session. + /// A UpdateSearcher instance for this session. + /// A UpdateSearcher instance can also be created by using the UpdateSearcher class. + public static UpdateSearcher CreateUpdateSearcher() => new(); + + /// Returns a pointer to a UpdateServiceManager instance for the session. + /// A pointer to a UpdateServiceManager instance for the session. + public static UpdateServiceManager CreateUpdateServiceManager() => new(); +} + +/// Contains the functionality of Automatic Updates. +public class AutomaticUpdates +{ + private readonly IAutomaticUpdates au = new(); + + /// Returns an instance. + /// An instance. + public AutomaticUpdatesResults? Results => au is IAutomaticUpdates2 u2 ? new AutomaticUpdatesResults(u2.Results) : null; + + /// Gets a that indicates whether all the components that Automatic Updates requires are available. + /// if all the components that Automatic Updates requires are available; otherwise, . + public bool ServiceEnabled => au.ServiceEnabled; + + /// Gets the configuration settings for Automatic Updates. + /// The returned object can be used to change the current settings and to read the current settings. + public AutomaticUpdatesSettings Settings => new(au.Settings); + + /// + /// Begins the Automatic Updates detection task if Automatic Updates is enabled. If any updates are detected, the installation behavior + /// is determined by the NotificationLevel property of the AutomaticUpdatesSettings instance. + /// + public void DetectNow() => au.DetectNow(); + + /// Enables all the components that Automatic Updates requires. + /// + /// This method requires administrator permissions. + /// + public void EnableService() => au.EnableService(); + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(au, flags); + + /// Pauses automatic updates. + /// + /// This method requires administrator permissions. + /// + /// Automatic Updates can be paused for only eight hours. This limit varies in different binary versions. Callers should call the Resume + /// method after calling as soon as they no longer need to pause automatic updating. + /// + /// + public void Pause() => au.Pause(); + + /// Restarts automatic updating if automatic updating is paused. + /// + /// This method requires administrator permissions. + /// Callers should call after calling the Pause method as soon as they no longer need to pause automatic updating. + /// + public void Resume() => au.Resume(); + + /// Displays a dialog box that contains settings for Automatic Updates. + /// + /// + /// A call to fails if the calling user is not logged on or does not have a desktop. A caller can also + /// programmatically modify Automatic Updates settings by using the Settings property. + /// + /// + /// The settings in the dialog box are read-only if the caller has insufficient security permissions or if the settings are enforced by a + /// domain administrator who is using Group Policy settings. + /// + /// + public void ShowSettingsDialog() => au.ShowSettingsDialog(); +} + +/// Contains the read-only properties that describe Automatic Updates. +public class AutomaticUpdatesResults +{ + private readonly IAutomaticUpdatesResults res; + + internal AutomaticUpdatesResults(IAutomaticUpdatesResults res) => this.res = res; + + /// + /// Gets the last time and Coordinated Universal Time (UTC) date when Automatic Updates successfully installed any updates, even if some + /// failures occurred. + /// + /// + /// Calls to LastInstallationSuccessDate by public users do not update this property. Only the AutomaticUpdates object will update this property. + /// + public DateTime? LastInstallationSuccessDate => (DateTime?)res.LastInstallationSuccessDate; + + /// Gets the last time and Coordinated Universal Time (UTC) date when AutomaticUpdates successfully searched for updates. + /// + /// If the date-time for the last successful update search is not known, returns . Otherwise, returns the of the last successful update search. + /// + public DateTime? LastSearchSuccessDate => (DateTime?)res.LastSearchSuccessDate; +} + +/// Contains the settings that are available in Automatic Updates. +public class AutomaticUpdatesSettings +{ + private readonly IAutomaticUpdatesSettings settings; + + internal AutomaticUpdatesSettings(IAutomaticUpdatesSettings settings) => this.settings = settings; + + /// + /// + /// Gets and sets a that indicates whether to include optional or recommended updates when a search for updates and + /// installation of updates is performed. + /// + /// + /// + /// Only administrators can set this property. + /// + /// The caller can modify the settings in AutomaticUpdatesSettings only if the ReadOnly property is . The property may change after the Refresh method is called. + /// + /// + public bool? IncludeRecommendedUpdates + { + get => settings is IAutomaticUpdatesSettings2 s2 ? s2.IncludeRecommendedUpdates : null; + set { if (settings is IAutomaticUpdatesSettings2 s2) s2.IncludeRecommendedUpdates = value ?? throw new NotImplementedException(); } + } + + /// + /// Gets and sets a that indicates whether non-administrators can perform some update-related actions without + /// administrator approval. + /// + /// + /// The NonAdministratorsElevated property controls whether non-administrative users are allowed to perform some additional actions + /// without elevation. It is equivalent to the “Allow all users to install updates on this computer” check box in the Windows Update + /// settings dialog. + /// + public bool? NonAdministratorsElevated + { + get => settings is IAutomaticUpdatesSettings3 s3 ? s3.NonAdministratorsElevated : null; + set { if (settings is IAutomaticUpdatesSettings3 s3) s3.NonAdministratorsElevated = value ?? throw new NotImplementedException(); } + } + + /// Gets and sets how users are notified about Automatic Update events. + public AutomaticUpdatesNotificationLevel NotificationLevel { get => settings.NotificationLevel; set => settings.NotificationLevel = value; } + + /// Gets a that indicates whether the Automatic Update settings are read-only. + /// + /// is if either of the following conditions is true: + /// + /// + /// The caller has insufficient security permissions to modify the Automatic Updates settings. + /// + /// + /// The current settings are enforced by Group Policy. + /// + /// + /// + /// The caller can modify the settings in AutomaticUpdatesSettings only if is The value of + /// may change after calling Refresh. + /// + /// + public bool ReadOnly => settings.ReadOnly; + + /// Gets a that indicates whether Group Policy requires the Automatic Updates service. + public bool Required => settings.Required; + + /// Gets and sets the days of the week on which Automatic Updates installs or uninstalls updates. + /// + /// The value of this property is ignored if the value of the NotificationLevel property is not . + /// + /// Note  Starting with Windows 8 and Windows Server 2012, is not supported and will return + /// unreliable values. If you try to modify , the operation will appear to succeed but will have no effect. + /// + /// + public AutomaticUpdatesScheduledInstallationDay ScheduledInstallationDay { get => settings.ScheduledInstallationDay; set => settings.ScheduledInstallationDay = value; } + + /// Gets and sets the time at which Automatic Updates installs or uninstalls updates. + /// + /// The time is set by using the following values. + /// + /// + /// Value + /// Time + /// + /// + /// 0 + /// 00:00 + /// + /// + /// 1 + /// 01:00 + /// + /// + /// 2 + /// 02:00 + /// + /// + /// 3 + /// 03:00 + /// + /// + /// 4 + /// 04:00 + /// + /// + /// 5 + /// 05:00 + /// + /// + /// 6 + /// 06:00 + /// + /// + /// 7 + /// 07:00 + /// + /// + /// 8 + /// 08:00 + /// + /// + /// 9 + /// 09:00 + /// + /// + /// 10 + /// 10:00 + /// + /// + /// 11 + /// 11:00 + /// + /// + /// 12 + /// 12:00 + /// + /// + /// 13 + /// 13:00 + /// + /// + /// 14 + /// 14:00 + /// + /// + /// 15 + /// 15:00 + /// + /// + /// 16 + /// 16:00 + /// + /// + /// 17 + /// 17:00 + /// + /// + /// 18 + /// 18:00 + /// + /// + /// 19 + /// 19:00 + /// + /// + /// 20 + /// 20:00 + /// + /// + /// 21 + /// 21:00 + /// + /// + /// 22 + /// 22:00 + /// + /// + /// 23 + /// 23:00 + /// + /// + /// The value of this property is ignored if the value of the NotificationLevel property is not . + /// + /// Note  Starting with Windows 8 and Windows Server 2012, is not supported and will + /// return unreliable values. If you try to modify , the operation will appear to succeed but will + /// have no effect. + /// + /// + public int ScheduledInstallationTime { get => settings.ScheduledInstallationTime; set => settings.ScheduledInstallationTime = value; } + + /// Determines whether a specific user or type of user has permission to perform a selected action. + /// An enumeration that indicates the type of user to verify permissions. + /// An enumeration that indicates the user's permission level. + /// if the user has the specified permission type; otherwise, . + /// + /// This method can be used to determine whether User Access Control (UAC) must be used to perform an action in the agent, which may + /// obviate the need for prompting if the user type does not have permission to perform the action. For example, unless the agent has + /// elevated permission, the ReadOnly property of the AutomaticUpdatesSettings object will always be . However, + /// even after a user has been elevated, the NotificationLevel (for example) may still be read-only due to Group Policy settings. The + /// method can determine this before elevation is done to prevent prompting in cases where the setting + /// cannot be changed. + /// + public bool CheckPermission([In] AutomaticUpdatesUserType userType, [In] AutomaticUpdatesPermissionType permissionType) => + (settings as IAutomaticUpdatesSettings2)?.CheckPermission(userType, permissionType) ?? throw new NotImplementedException(); + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes + /// that implement the UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(settings, flags); + + /// Retrieves the latest Automatic Updates settings. + /// + /// Calling resets any setting changes that have not been saved by using the Save method. + /// + /// Note  On Windows RT, you can no longer use the AutomaticUpdatesSettings.Save method to configure Windows Update settings + /// programmatically. The configuration operation fails if you use to set any value other than 4 (aunlScheduledInstallation). + /// + /// + public void Refresh() => settings.Refresh(); + + /// Applies the current Automatic Updates settings. + /// + /// Saving settings with a NotificationLevel value other than Disabled starts the Automatic Updates service. + /// + /// Note  On Windows RT, you can no longer use the method to configure Windows Update settings + /// programmatically. The configuration operation fails if you use to set any value other than 4 (aunlScheduledInstallation). + /// + /// + public void Save() => settings.Save(); +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class BoolCriteria : FluentQueryBase +{ + internal BoolCriteria(FluentQueryBase prior, bool allowed) : base(prior) => Allowed = allowed ? 1 : 0; + + /// Handles the 'IsAssigned' query value. + public QueryOperator Assigned => new(this, $"IsAssigned={Allowed}"); + + /// Handles the 'AutoSelectOnWebSites' query value. + public QueryOperator AutoSelectOnWebSites => new(this, $"AutoSelectOnWebSites={Allowed}"); + + /// Handles the 'BrowseOnly' query value. + public QueryOperator BrowseOnly => new(this, $"BrowseOnly={Allowed}"); + + /// Handles the 'IsHidden' query value. + public QueryOperator Hidden => new(this, $"IsHidden={Allowed}"); + + /// Handles the 'IsInstalled' query value. + public QueryOperator Installed => new(this, $"IsInstalled={Allowed}"); + + /// Handles the 'IsPresent' query value. + public QueryOperator Present => new(this, $"IsPresent={Allowed}"); + + /// Handles the 'RebootRequired' query value. + public QueryOperator RebootRequired => new(this, $"RebootRequired={Allowed}"); + + internal int Allowed { get; set; } +} + +/// Represents the category to which an update belongs. +public class Category +{ + private readonly ICategory cat; + + internal Category(ICategory cat) => this.cat = cat; + + /// Gets the identifier of the category. + [DefaultValue(null)] + public string? CategoryID => cat.CategoryID; + + /// Gets a collection that contains the child categories of this category. + public IReadOnlyCollection Children => new CategoryCollection(cat.Children); + + /// Gets the description of the category. + /// + /// + /// A Categories property exists for the Update object. And, a Categories property exists for the UpdateHistoryEntry object. Therefore, + /// the information that is used by the localized properties of the Category object depends on the Windows Update Agent (WUA) object that + /// owns the object. + /// + /// + /// If the Category object is returned from the Categories property of Update, the object follows the localization + /// rules of the object. In this case, if the UpdateSearcher object is created by using the + /// UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the language that is specified by the + /// UserLocale property of the UpdateSession object of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of the UpdateSession object, or if the UpdateSearcher object is + /// not created by using the UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the default + /// user interface (UI) language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of + /// the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// If the Category object is returned from the Categories property of the UpdateHistoryEntry object, the object + /// follows the localization rules of the object. The information that this property returns is for the + /// default UI language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of the + /// computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + [DefaultValue(null)] + public string? Description => cat.Description; + + /// Gets an object that contains information about the image that is associated with the category. + /// + /// + /// A Categories property exists for the Update object. And, a Categories property exists for the UpdateHistoryEntry object. Therefore, + /// the information that is used by the localized properties of the Category object depends on the Windows Update Agent (WUA) object that + /// owns . + /// + /// + /// If the Category instance is returned from the Categories property of Update, the class follows the + /// localization rules of the object. In this case, if the UpdateSearcher instance is created by using the + /// UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the language that is specified by the + /// UserLocale property of the UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of the UpdateSession instance, or if the IUpdateSearcher object + /// is not created by using the UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the default + /// user interface (UI) language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of + /// the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// If the Category instance is returned from the Categories property of the UpdateHistoryEntry instance, the + /// object follows the localization rules of the class. The information that this property returns is + /// for the default UI language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of + /// the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + [DefaultValue(null)] + public ImageInformation? Image => cat.Image is null ? null : new(cat.Image); + + /// Gets the localized name of the category. + /// + /// + /// A Categories property exists for the Update instance. And, a Categories property exists for the UpdateHistoryEntry instance. + /// Therefore, the information that is used by the localized properties of the Category instance depends on the Windows Update Agent + /// (WUA) object that owns the class. + /// + /// + /// If the Category instance is returned from the Categories property of IUpdate, the class follows the + /// localization rules of the class. In this case, if the UpdateSearcher instance is created by using the + /// UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the language that is specified by the + /// UserLocale property of the UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of the UpdateSession instance, or if the IUpdateSearcher object + /// is not created by using the UpdateSession.CreateUpdateSearcher method, the information that this property returns is for the default + /// user interface (UI) language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of + /// the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// If the Category instance is returned from the Categories property of the UpdateHistoryEntry instance, the + /// object follows the localization rules of the class. The information that this property returns is + /// for the default UI language of the user. If the default UI language of the user is unavailable, WUA uses the default UI language of + /// the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + public string Name => cat.Name; + + /// Gets the recommended display order of this category among its sibling categories. + [DefaultValue(0)] + public int Order => cat.Order; + + /// Gets the type of the category. + /// The following list identifies the possible category types: + public string Type => cat.Type; + + /// Gets an object that describes the parent category of this category. + public Category? GetParent() => cat.Parent is null ? null : new(cat.Parent); + + /// Gets a collection of updates that immediately belong to the category. + /// The returned updates are applicable to the computer. They may or may not be installed on that computer. + public IReadOnlyCollection GetUpdates() => new UpdateCollection(cat.Updates); +} + +/// The class represents an ordered read-only list of Category instances. +public class CategoryCollection : VirtualReadOnlyList +{ + internal CategoryCollection(ICategoryCollection? coll) : base(new CollectionMethods(coll)) + { + } + + private class CollectionMethods(ICategoryCollection? c) : IVirtualReadOnlyListMethods + { + public readonly ICategoryCollection? src = c; + + public int GetItemCount() => src?.Count ?? 0; + + public bool TryGet(int index, [NotNullWhen(true)] out Category? value) + { + ICategory? cat = index >= 0 && index < GetItemCount() ? src![index] : null; + value = cat is not null ? new Category(cat) : null; + return value is not null; + } + } +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class ContainsCriteria : FluentQueryBase +{ + internal ContainsCriteria(FluentQueryBase prior) : base(prior) + { + } + + /// Handles the 'CategoryIDs' query value. + public QueryOperator Category(Guid catId) => new(this, $"CategoryIDs contains '{catId:D}'"); +} + +/// Represents the progress of an asynchronous download operation. +public class DownloadProgress +{ + private readonly IDownloadProgress prog; + + internal DownloadProgress(IDownloadProgress prog) => this.prog = prog; + + /// + /// Gets a string that specifies how much data has been transferred for the content file or files of the update that is being downloaded, + /// in bytes. + /// + public decimal CurrentUpdateBytesDownloaded => prog.CurrentUpdateBytesDownloaded; + + /// + /// Gets a string that estimates how much data should be transferred for the content file or files of the update that is being + /// downloaded, in bytes. + /// + public decimal CurrentUpdateBytesToDownload => prog.CurrentUpdateBytesToDownload; + + /// Gets a DownloadPhase enumeration value that specifies the phase of the download that is currently in progress. + public DownloadPhase CurrentUpdateDownloadPhase => prog.CurrentUpdateDownloadPhase; + + /// + /// Gets a zero-based index value that specifies the update that is currently being downloaded when multiple updates have been selected. + /// + public int CurrentUpdateIndex => prog.CurrentUpdateIndex; + + /// Gets an estimate of the percentage of the current update that has been downloaded. + public int CurrentUpdatePercentComplete => prog.CurrentUpdatePercentComplete; + + /// Gets an estimate of the percentage of all the updates that have been downloaded. + public int PercentComplete => prog.PercentComplete; + + /// Gets a string that specifies the total amount of data that has been downloaded, in bytes. + public decimal TotalBytesDownloaded => prog.TotalBytesDownloaded; + + /// Gets a string that represents the estimate of the total amount of data that will be downloaded, in bytes. + public decimal TotalBytesToDownload => prog.TotalBytesToDownload; + + /// Returns the result of the download of a specified update. + /// A zero-based index value that specifies an update. + /// A UpdateDownloadResult instance that contains information about the specified update. + public UpdateDownloadResult GetUpdateResult([In] int updateIndex) => new(prog.GetUpdateResult(updateIndex)); +} + +/// The class represents the result of a download operation. +public class DownloadResult +{ + private readonly IDownloadResult res; + + internal DownloadResult(IDownloadResult res) => this.res = res; + + /// Gets the exception code number if an exception code number is raised during the download. + [DefaultValue(0)] + public HRESULT HResult => res.HResult; + + /// Gets an OperationResultCode enumeration that specifies the result of the download. + public OperationResultCode ResultCode => res.ResultCode; + + /// Returns a UpdateDownloadResult instance that contains the download information for a specified update. + /// The index of the update. + /// A UpdateDownloadResult instance that contains the results for the specified update. + public UpdateDownloadResult GetUpdateResult([In] int updateIndex) => new(res.GetUpdateResult(updateIndex)); +} + +/// Fluent helper class. Not intended for use. +public abstract class FluentQueryBase +{ + /// The searcher + protected readonly UpdateSearcher searcher; + /// The query + protected StringBuilder query; + + internal FluentQueryBase(UpdateSearcher searcher) + { this.searcher = searcher; query = new StringBuilder(1024); } + + internal FluentQueryBase(FluentQueryBase prior, string? stmt = null) + { searcher = prior.searcher; query = prior.query; if (stmt is not null) query.Append(stmt + ' '); } + + //public override string ToString() => query.ToString().Trim(); +} + +/// Contains information about a localized image that is associated with an update or a category. +public class ImageInformation +{ + private readonly IImageInformation img; + + internal ImageInformation(IImageInformation img) => this.img = img; + + /// Gets the alternate text for the image. + public string AltText => img.AltText; + + /// Gets the size of the image, in pixels. + public SIZE Size => new(img.Width, img.Height); + + /// Gets the source location of the image. + public string Source => img.Source; +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class InclCriteria : FluentQueryBase +{ + internal InclCriteria(FluentQueryBase prior, bool eq) : base(prior) => Eq = eq ? "=" : "!="; + + internal string Eq { get; set; } + + /// Handles the 'Type' query value. + public QueryOperator Type(string type) => new(this, $"Type{Eq}'{type}'"); + + /// Handles the 'UpdateID' query value. + public QueryOperator UpdateID(Guid id) => new(this, $"UpdateID{Eq}'{id:D}'"); +} + +/// Represents the installation and uninstallation options of an update. +public class InstallationBehavior +{ + private readonly IInstallationBehavior beh; + + internal InstallationBehavior(IInstallationBehavior beh) => this.beh = beh; + + /// + /// Gets a thast indicates whether the installation or uninstallation of an update can prompt for user input. + /// + public bool CanRequestUserInput => beh.CanRequestUserInput; + + /// + /// Gets an InstallationImpact enumeration that indicates how the installation or uninstallation of the update affects the computer. + /// + public InstallationImpact Impact => beh.Impact; + + /// + /// Gets an InstallationRebootBehavior enumeration that specifies the restart behavior that occurs when you install or uninstall the update. + /// + public InstallationRebootBehavior RebootBehavior => beh.RebootBehavior; + + /// Gets a that indicates whether the installation or uninstallation of an update requires network connectivity. + public bool RequiresNetworkConnectivity => beh.RequiresNetworkConnectivity; +} + +/// Represents the progress of an asynchronous installation or uninstallation. +public class InstallationProgress +{ + private readonly IInstallationProgress prog; + + internal InstallationProgress(IInstallationProgress prog) => this.prog = prog; + + /// + /// Gets a zero-based index value. This value specifies the update that is currently being installed or uninstalled when multiple updates + /// have been selected. + /// + public int CurrentUpdateIndex => prog.CurrentUpdateIndex; + + /// Gets how far the installation or uninstallation process for the current update has progressed, as a percentage. + public int CurrentUpdatePercentComplete => prog.CurrentUpdatePercentComplete; + + /// Gets how far the overall installation or uninstallation process has progressed, as a percentage. + public int PercentComplete => prog.PercentComplete; + + /// Returns the result of the installation or uninstallation of a specified update. + /// A zero-based index value that specifies an update. + /// A UpdateInstallationResult instance that contains information about a specified update. + /// + /// You must make repeated calls to the method to track the progress of a download. You must do this + /// because the UpdateInstallationResult instance is not automatically updated during a download. + /// + public UpdateInstallationResult GetUpdateResult([In] int updateIndex) => new(prog.GetUpdateResult(updateIndex)); +} + +/// Represents the result of an installation or uninstallation. +public class InstallationResult +{ + private readonly IInstallationResult res; + + internal InstallationResult(IInstallationResult res) => this.res = res; + + /// Gets the of the exception, if any, that is raised during the installation. + public HRESULT HResult => res.HResult; + + /// + /// Gets a that indicates whether you must restart the computer to complete the installation or uninstallation of an update. + /// + public bool RebootRequired => res.RebootRequired; + + /// Gets an OperationResultCode value that specifies the result of an operation on an update. + public OperationResultCode ResultCode => res.ResultCode; + + /// Returns a UpdateInstallationResult instance that contains the installation results for a specified update. + /// The index of an update. + /// An object that contains results for a specified update. + public UpdateInstallationResult GetUpdateResult(int updateIndex) => new(res.GetUpdateResult(updateIndex)); +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class QueryCondition : FluentQueryBase +{ + internal QueryCondition(UpdateSearcher updateSearcher) : base(updateSearcher) + { + } + + internal QueryCondition(FluentQueryBase prior, string? stmt = null) : base(prior, stmt) + { + } + + /// Handles query values using 'contains'. + public ContainsCriteria Contains => new(this); + + /// Handles query values using '!='. + public InclCriteria Excludes => new(this, false); + + /// Handles query values using parameters. + public SetCriteria Has => new(this); + + /// Handles query values using '='. + public BoolCriteria Is => new(this, true); + + /// Handles query values using '!='. + public BoolCriteria Not => new(this, false); +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class QueryOperator : FluentQueryBase +{ + internal QueryOperator(FluentQueryBase prior, string criteria) : base(prior, criteria) + { + } + + /// Handles join operations for queries using a logical AND. + public QueryCondition And => new(this, "and"); + + /// Handles join operations for queries using a logical OR. + public QueryCondition Or => new(this, "or"); + + /// Performs a synchronous search for updates. The search uses the search options that are currently configured. + /// + /// A SearchResult instance that contains the following: + /// + /// + /// The result of an operation + /// + /// + /// A collection of updates that match the search criteria + /// + /// + /// + public SearchResult Search() + { + System.Diagnostics.Debug.WriteLine(query); + return searcher.Search(query.ToString()); + } +} + +/// Represents the result of a search. +public class SearchResult +{ + private readonly ISearchResult res; + + internal SearchResult(ISearchResult r) => res = r; + + /// Gets an OperationResultCode enumeration that specifies the result of a search. + public OperationResultCode ResultCode => res.ResultCode; + + /// Gets a collection of the root categories that are currently available on the computer. + public IReadOnlyCollection RootCategories => new CategoryCollection(res.RootCategories); + + /// Gets a collection of the updates that result from a search. + public IReadOnlyList Updates => new UpdateCollection(res.Updates); + + /// Gets a collection of the warnings that result from a search. + public IReadOnlyCollection Warnings => res.Warnings?.Cast().Select(e => new UpdateException(e)).ToList() ?? []; +} + +/// +/// Fluent query item for Windows Update searches. This class is used to build a query for the method. +/// +/// +public class SetCriteria : FluentQueryBase +{ + internal SetCriteria(FluentQueryBase prior, bool eq = true) : base(prior) => Eq = eq ? "=" : "!="; + + internal string Eq { get; set; } + + /// Handles the 'DeploymentAction' query value. + public QueryOperator DeploymentAction(string action) => new(this, $"DeploymentAction='{action}'"); + + /// Handles the 'RevisionNumber' query value. + public QueryOperator RevisionNumber(int rev) => new(this, $"RevisionNumber={rev}"); + + /// Handles the 'Type' query value. + public QueryOperator Type(string type) => new(this, $"Type{Eq}'{type}'"); + + /// Handles the 'UpdateID' query value. + public QueryOperator UpdateID(Guid id) => new(this, $"UpdateID{Eq}'{id:D}'"); +} + +/// Represents an ordered list of strings. +public class StringCollection : VirtualList, IStringCollection +{ + /// Initializes a new instance of the class. + /// The values with which to initiate the list. + public StringCollection(IEnumerable values) : this((IStringCollection?)null) + { + foreach (var s in values) + Add(s); + } + + /// Initializes a new instance of the class. + public StringCollection() : this((IStringCollection?)null) + { + } + + internal StringCollection(IStringCollection? coll = null) : base(new StringCollectionMethods(coll)) + { + } + + internal IStringCollection Interface => ((StringCollectionMethods)impl).coll; + + private class StringCollectionMethods(IStringCollection? c) : IVirtualListMethods + { + public readonly IStringCollection coll = c ?? new IStringCollection(); + + public void AddItem(string item) => coll.Add(item); + + public int GetItemCount() => coll.Count; + + public void InsertItemAt(int index, string item) => coll.Insert(index, item); + + public void RemoveItemAt(int index) => coll.RemoveAt(index); + + public void SetItemAt(int index, string value) => coll[index] = value; + + public bool TryGet(int index, [NotNullWhen(true)] out string? value) + { + value = index >= 0 && index < coll.Count ? coll[index] : null; + return value is not null; + } + } + + IEnumerator IStringCollection.GetEnumerator() => Interface.GetEnumerator(); + bool IStringCollection.ReadOnly => Interface.ReadOnly; + int IStringCollection.Add(string value) => Interface.Add(value); + IStringCollection IStringCollection.Copy() => Interface.Copy(); +} + +/// Contains information about the specified computer. This information is relevant to the Windows Update Agent (WUA). +public class SystemInformation +{ + private readonly ISystemInformation info = new(); + + /// Gets a hyperlink to technical support information for OEM hardware. + [DefaultValue("")] + public string OemHardwareSupportLink => info.OemHardwareSupportLink; + + /// + /// Gets a that indicates whether a system restart is required to complete the installation or uninstallation of one + /// or more updates. + /// + [DefaultValue(false)] + public bool RebootRequired => info.RebootRequired; +} + +/// Contains the properties and methods that are available to an update. +/// +/// If the BundledUpdates property contains an UpdateCollection, some properties and methods of the update may only be available on the +/// bundled updates, for example, DownloadContents or CopyFromCache. +/// +public class Update +{ + /// The update object. + protected internal readonly IUpdate upd; + + internal Update(IUpdate upd) => this.upd = upd; + + /// Gets a value indicating the automatic download mode of update. + /// The AutoDownload property indicates whether the update will be automatically downloaded by Automatic Updates. + public AutoDownloadMode AutoDownload => (upd as IUpdate5)?.AutoDownload ?? AutoDownloadMode.adLetWindowsUpdateDecide; + + /// Gets a value indicating the automatic selection mode of update in the Control Panel of Windows Update. + /// + /// The AutoSelection property indicates whether the update will be automatically selected when the user views the available updates in + /// the Windows Update user interface. + /// + public AutoSelectionMode AutoSelection => (upd as IUpdate5)?.AutoSelection ?? AutoSelectionMode.asLetWindowsUpdateDecide; + + /// Gets a that indicates whether the update is flagged to be automatically selected by Windows Update. + public bool AutoSelectOnWebSites => upd.AutoSelectOnWebSites; + + /// Gets a that indicates whether an update can be discovered only by browsing through the available updates. + public bool? BrowseOnly => (upd as IUpdate3)?.BrowseOnly; + + /// Gets an object that contains information about the ordered list of the bundled updates for the update. + public IReadOnlyList BundledUpdates => new UpdateCollection(upd.BundledUpdates); + + /// Gets a that indicates whether the source media of the update is required for installation or uninstallation. + public bool CanRequireSource => upd.CanRequireSource; + + /// Gets a collection of categories to which the update belongs. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property of the UpdateSession instance of the session that was used + /// to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that this property returns is for the default user interface + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + /// Because there is a property of IUpdate and a Categories property of UpdateHistoryEntry, the information that + /// is used by the localized properties of the Category instance depend on the WUA object that owns the class. If + /// the class is returned from the property of , it follows the + /// localization rules of . If the class is returned from the + /// property of , it follows the localization rules of . + /// + /// + public IReadOnlyCollection Categories => new CategoryCollection(upd.Categories); + + /// Gets a collection of common vulnerabilities and exposures (CVE) IDs that are associated with the update. + public IReadOnlyList CveIDs => new StringCollection((upd as IUpdate3)?.CveIDs); + + /// Gets the date by which the update must be installed. + /// + /// + /// In COM, if the update has a deadline, the return value is of type VT_DATE and contains a DATE value that specifies the deadline. + /// Otherwise, the return value is of type VT_EMPTY. + /// + /// In the Microsoft .NET Framework, the return value is if the update has no deadline. + /// + public DateTime? Deadline => upd.Deadline is null ? null : (DateTime)upd.Deadline; + + /// Gets a that indicates whether delta-compressed content is available on a server for the update. + public bool DeltaCompressedContentAvailable => upd.DeltaCompressedContentAvailable; + + /// + /// Gets a that indicates whether to prefer delta-compressed content during the download and install or uninstall of + /// the update if delta-compressed content is available. + /// + public bool DeltaCompressedContentPreferred => upd.DeltaCompressedContentPreferred; + + /// Gets the action for which the update is deployed. + public DeploymentAction DeploymentAction => upd.DeploymentAction; + + /// Gets the localized description of the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string? Description => upd.Description; + + /// Gets file information about the download contents of the update. + public IReadOnlyList DownloadContents => upd.DownloadContents?.Cast().Select(c => new UpdateDownloadContent(c)).ToList() ?? []; + + /// Gets the suggested download priority of the update. + [DefaultValue(DownloadPriority.dpNormal)] + public DownloadPriority DownloadPriority => upd.DownloadPriority; + + /// + /// + /// Gets a that indicates whether the Microsoft Software License Terms that are associated with the update are + /// accepted for the computer. + /// + /// + public bool EulaAccepted => upd.EulaAccepted; + + /// Gets the full localized text of the Microsoft Software License Terms that are associated with the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string? EulaText => upd.EulaText; + + /// Gets the install handler of the update. + /// + /// The valid values for the property include the following: + /// + /// + /// The Command Line Installation Handlerhttp://schemas.microsoft.com/msus/2002/12/UpdateHandlers/CommandLineInstallation + /// + /// + /// The Inf Based Installation Handlerhttp://schemas.microsoft.com/msus/2002/12/UpdateHandlers/InfBasedInstallation + /// + /// + /// The Windows Installer Installation Handlerhttp://schemas.microsoft.com/msus/2002/12/UpdateHandlers/WindowsInstaller + /// + /// + /// + /// The Package Installer for Microsoft Windows Operating Systems and Windows Components (update.exe) Installation Handlerhttp://schemas.microsoft.com/msus/2002/12/UpdateHandlers/WindowsPatch + /// + /// + /// + /// The Component Based Servicing (CBS) Handlerhttp://schemas.microsoft.com/msus/2002/12/UpdateHandlers/Cbs + /// + /// + /// + public string? HandlerID => upd.HandlerID; + + /// Gets an object that contains the unique identifier of the update. + public UpdateIdentity Identity => new(upd.Identity); + + /// Gets an object that contains information about an image that is associated with the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// This API can return a null pointer as the output, even when the return value is S_OK. + /// + public ImageInformation? Image => upd.Image is null ? null : new(upd.Image); + + /// Gets an object that contains the installation options of the update. + /// + /// If the current update represents a bundle, the property of the bundle will be determined by the + /// property of the child updates of the bundle. This API can return a null pointer as the output, + /// even when the return value is S_OK. + /// + public InstallationBehavior InstallationBehavior => new(upd.InstallationBehavior); + + /// Gets a that indicates whether the update is a beta release. + public bool IsBeta => upd.IsBeta; + + /// Gets a that indicates whether all the update content is cached on the computer. + public bool IsDownloaded => upd.IsDownloaded; + + /// + /// + /// Gets a that indicates whether an update is hidden by a user. Administrators, users, and power users can retrieve + /// the value of this property. However, only administrators and members of the Power Users administrative group can set the value of + /// this property. + /// + /// + /// An attempt to mark a mandatory update as hidden causes an error. + public bool IsHidden { get => upd.IsHidden; set => upd.IsHidden = value; } + + /// Gets a that indicates whether the update is installed on a computer when the search is performed. + public bool IsInstalled => upd.IsInstalled; + + /// Gets a that indicates whether the installation of the update is mandatory. + /// + /// If you try to mark a mandatory update as hidden, an error occurs. + /// + /// Mandatory updates are updates to the Windows Update Agent (WUA) infrastructure. WUA may not require all mandatory updates to continue + /// operating. However, these updates frequently improve performance or increase the number of products that WUA can offer. We recommend + /// that you install all mandatory updates. + /// + /// + public bool IsMandatory => upd.IsMandatory; + + /// Gets a that indicates whether an update is present on a computer. + /// + /// + /// An update is considered present if it is installed for one or more products. For example, if an update applies to both Microsoft + /// Office Word and to Microsoft Office Excel, the property returns if the update is + /// installed for one or both of the products. + /// + /// + /// If an update applies to only one product, the and IsInstalled properties are equivalent. An update is + /// considered installed if the update is installed for all the products to which it applies. + /// + /// + /// If returns and IsInstalled returns , the update can be + /// uninstalled for the product that installed it. + /// + /// + public bool? IsPresent => (upd as IUpdate2)?.IsPresent; + + /// Gets a that indicates whether a user can uninstall the update from a computer. + public bool IsUninstallable => upd.IsUninstallable; + + /// Gets a collection of Microsoft Knowledge Base article IDs that are associated with the update. + public IReadOnlyList KBArticleIDs => new StringCollection(upd.KBArticleIDs); + + /// Gets an object that contains the languages that are supported by the update. + /// + /// This property refers to the language of the update itself. The language that is used for the title and description of the update is + /// not necessarily the language of the update itself. + /// + public IReadOnlyList Languages => new StringCollection(upd.Languages); + + /// + /// Gets the last published date of the update, in Coordinated Universal Time (UTC) date and time, on the server that deploys the update. + /// + /// + /// On computers that are running Windows XP, the property retrieves the same date and time that + /// are retrieved by the CreationDate property of the UpdateApproval class. The CreationDate property is used on computers + /// that are running Windows Server 2003. + /// + public DateTime LastDeploymentChangeTime => upd.LastDeploymentChangeTime; + + /// Gets the maximum download size of the update. + /// + /// The MinDownloadSize property of an update is always downloaded. However, the property is not always + /// downloaded. The property is downloaded based on the configuration of the computer that receives the update. + /// + public decimal MaxDownloadSize => upd.MaxDownloadSize; + + /// Gets the minimum download size of the update. + /// + /// The property of an update is always downloaded. However, the MaxDownloadSize property is not always + /// downloaded. The property is downloaded based on the configuration of the computer that receives the update. + /// + public decimal MinDownloadSize => upd.MinDownloadSize; + + /// Gets a collection of language-specific strings that specify the hyperlinks to more information about the update. + public IReadOnlyList MoreInfoUrls => new StringCollection(upd.MoreInfoUrls); + + /// Gets the Microsoft Security Response Center severity rating of the update. + /// + /// + /// The following ratings are the possible severity ratings of a security issue that is fixed by an update. These ratings were revised by + /// the Microsoft Security Response Center in November 2002. + /// + /// + /// + /// Term + /// Description + /// + /// + /// Critical + /// A security issue whose exploitation could allow the propagation of an Internet worm without user action. + /// + /// + /// Important + /// + /// A security issue whose exploitation could result in compromise of the confidentiality, integrity, or availability of users' data, or + /// of the integrity or availability of processing resources. + /// + /// + /// + /// Moderate + /// + /// Exploitation is mitigated to a significant degree by factors such as default configuration, auditing, or difficulty of exploitation. + /// + /// + /// + /// Low + /// A security issue whose exploitation is extremely difficult, or whose impact is minimal. + /// + /// + /// + public string? MsrcSeverity => upd.MsrcSeverity; + + /// Gets a that indicates whether this is a per-user update. + /// + /// Per-user updates are designed to alter the current user’s environment only; not the environment of the machine as a whole. For + /// example, an update which only alters files in the current user’s user directory could be a per-user update; an update which alters + /// files in the Program Files directory or the Windows directory would not be a per-user update. Per-user updates are currently not + /// processed by Automatic Updates or displayed in the Windows Update user interface. Instead, they are only available to callers who + /// specifically request them in searches by using the UpdateSearcher instance. On computers running versions of Windows Update Agent + /// that do not implement the Update instance, only per-machine updates will be available; per-user updates will never be detected. + /// + public bool PerUser => (upd as IUpdate4)?.PerUser ?? false; + + /// + /// + /// Gets a that indicates whether a system restart is required on a computer to complete the installation or the + /// uninstallation of an update. + /// + /// + public bool? RebootRequired => (upd as IUpdate2)?.RebootRequired; + + /// Gets the recommended CPU speed used to install the update, in megahertz (MHz). + /// + /// The following properties of the Update instance return 0 (zero) when the information is not available: + /// + /// + /// + /// + /// + /// RecommendedHardDiskSpace + /// + /// + /// RecommendedMemory + /// + /// + /// + public int RecommendedCpuSpeed => upd.RecommendedCpuSpeed; + + /// + /// + /// Gets the recommended free space that should be available on the hard disk before you install the update. The free space is specified + /// in megabytes (MB). + /// + /// + /// + /// The following properties of the Update instance return 0 (zero) when the information is not available: + /// + /// + /// RecommendedCpuSpeed + /// + /// + /// + /// + /// + /// RecommendedMemory + /// + /// + /// + public int RecommendedHardDiskSpace => upd.RecommendedHardDiskSpace; + + /// + /// + /// Gets the recommended physical memory size that should be available in your computer before you install the update. The physical + /// memory size is specified in megabytes (MB). + /// + /// + /// + /// The following properties of the Update instance return 0 (zero) when the information is not available: + /// + /// + /// RecommendedCpuSpeed + /// + /// + /// RecommendedHardDiskSpace + /// + /// + /// + /// + /// + /// + public int RecommendedMemory => upd.RecommendedMemory; + + /// Gets the localized release notes for the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string? ReleaseNotes => upd.ReleaseNotes; + + /// Gets a collection of string values that contain the security bulletin IDs that are associated with the update. + public IReadOnlyList SecurityBulletinIDs => new StringCollection(upd.SecurityBulletinIDs); + + /// + /// Gets a collection of update identifiers. This collection of identifiers specifies the updates that are superseded by the update. + /// + public IReadOnlyList SupersededUpdateIDs => new StringCollection(upd.SupersededUpdateIDs); + + /// Gets a hyperlink to the language-specific support information for the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string? SupportUrl => upd.SupportUrl; + + /// Gets the localized title of the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string Title => upd.Title; + + /// Gets the type of the update. + public UpdateType Type => upd.Type; + + /// Gets an object that contains the uninstallation options for the update. + /// This API can return a null pointer as the output, even when the return value is S_OK. + public InstallationBehavior? UninstallationBehavior => upd.UninstallationBehavior is null ? null : new(upd.UninstallationBehavior); + + /// Gets the uninstallation notes for the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public string? UninstallationNotes => upd.UninstallationNotes; + + /// Gets an object that contains the uninstallation steps for the update. + /// + /// + /// If the UpdateSearcher instance is created by using the UpdateSession.CreateUpdateSearcher method, the information that this property + /// returns is for the language that is specified by the UserLocale property. This is the UserLocale property of the + /// UpdateSession instance of the session that is used to create . + /// + /// + /// If a language preference is not specified by the UserLocale property of UpdateSession, or if the UpdateSearcher instance is not + /// created by using UpdateSession.CreateUpdateSearcher, the information that is returned by this property is for the default user object + /// (UI) language of the user. If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI + /// language of the computer. If the default language of the computer is unavailable, WUA uses the language that the provider of the + /// update recommends. + /// + /// + public IReadOnlyList UninstallationSteps => new StringCollection(upd.UninstallationSteps); + + /// + /// Accepts the Microsoft Software License Terms that are associated with Windows Update. Administrators and power users can call this method. + /// + public void AcceptEula() => upd.AcceptEula(); + + /// Copies the contents of an update to a specified path. + /// The path of the location where the update contents are to be copied. + /// + /// Reserved for future use. + /// You must set to or . + /// + /// + /// To copy bundled updates, call this method on the individual updates that are bundled in this update. + /// + /// We don't recommend or support the use of the Update.CopyFromCache and Update.CopyToCache methods to move + /// downloaded updates from one computer to another computer. When the Windows Update Agent (WUA) downloads an update, it might only + /// download the portions of the update’s payload that are necessary for a particular client computer. The necessary portions of the + /// update’s payload can often vary from one computer to another computer, even if the computers have similar hardware and software + /// configurations. Update.CopyToCache only works if the provided files are an exact match for the files that Windows Update + /// would have normally downloaded on that computer; if you called Update.CopyFromCache to obtain the files on a different + /// computer, the files are likely not to match the files that Windows Update would have normally downloaded so + /// Update.CopyToCache might fail. + /// + /// + public void CopyFromCache(string path, bool toExtractCabFiles) => upd.CopyFromCache(path, toExtractCabFiles); + + /// Copies files for an update from a specified source location to the internal Windows Update Agent (WUA) download cache. + /// + /// A StringCollection instance that represents a collection of strings that contain the full paths of the files for an update. + /// + /// The strings must give the full paths of the files that are being copied. The strings cannot give only the directory that contains the files. + /// + /// + /// + /// This method returns if the object that is implementing the object has been locked down. + /// + /// We don't recommend or support the use of the Update.CopyFromCache and Update.CopyToCache methods to move + /// downloaded updates from one computer to another computer. When the Windows Update Agent (WUA) downloads an update, it might only + /// download the portions of the update’s payload that are necessary for a particular client computer. The necessary portions of the + /// update’s payload can often vary from one computer to another computer, even if the computers have similar hardware and software + /// configurations. Update.CopyToCache only works if the provided files are an exact match for the files that Windows Update + /// would have normally downloaded on that computer; if you called Update.CopyFromCache to obtain the files on a different + /// computer, the files are likely not to match the files that Windows Update would have normally downloaded so + /// Update.CopyToCache might fail. + /// + /// + public void CopyToCache(IList pFiles) + { + if (upd is IUpdate2 u) + { + StringCollection sc = new(pFiles); + u.CopyToCache(sc.Interface); + } + else + throw new NotImplementedException(); + } +} + +/// Represents an ordered list of updates. +/// +/// You can create an instance of this object by using the UpdateCollection class. Use the Microsoft.Update.UpdateColl program identifier to +/// create the object. +/// +public class UpdateCollection : VirtualList, ICloneable //, IUpdateCollection +{ + /// Initializes a new instance of the class. + public UpdateCollection() : this((IUpdateCollection?)null) + { + } + + /// Initializes a new instance of the class. + public UpdateCollection(IEnumerable items) : this((IUpdateCollection?)null) + { + foreach (var i in items) + Add(i); + } + + internal UpdateCollection(IUpdateCollection? coll = null) : base(new UpdateCollectionMethods(coll ?? new IUpdateCollection())) + { + } + + /// Gets the underlying interface. + /// The interface. + public IUpdateCollection Interface => ((UpdateCollectionMethods)impl).coll; + + /// + public override IEnumerator GetEnumerator() => Interface.Cast().Select(Conv).GetEnumerator(); + + private static Update Conv(IUpdate iupd) => iupd.Type == UpdateType.utDriver && iupd is IWindowsDriverUpdate wdu ? new WindowsDriverUpdate(wdu) : new Update(iupd); + + /// Creates a shallow read/write copy of the collection. + /// A shallow read/write copy of the collection. + public UpdateCollection Clone() => new(Interface.Copy()); + + /// + object ICloneable.Clone() => Clone(); + + private class UpdateCollectionMethods(IUpdateCollection? c) : IVirtualListMethods + { + public readonly IUpdateCollection coll = c ?? new IUpdateCollection(); + + public void AddItem(Update item) => coll.Add(item.upd); + + public int GetItemCount() => coll.Count; + + public void InsertItemAt(int index, Update item) => coll.Insert(index, item.upd); + + public void RemoveItemAt(int index) => coll.RemoveAt(index); + + public void SetItemAt(int index, Update value) => coll[index] = value.upd; + + public bool TryGet(int index, [NotNullWhen(true)] out Update? value) + { + var iupd = index >= 0 && index < coll.Count ? coll[index] : null; + value = iupd is not null ? Conv(iupd) : null; + return value is not null; + } + } + + /*IUpdate IUpdateCollection.this[int index] { get => Interface[index]; set => Interface[index] = value; } + IEnumerator IUpdateCollection.GetEnumerator() => Interface.GetEnumerator(); + bool IUpdateCollection.ReadOnly => Interface.ReadOnly; + int IUpdateCollection.Add(IUpdate value) => Interface.Add(value); + IUpdateCollection IUpdateCollection.Copy() => Interface.Copy(); + void IUpdateCollection.Insert(int index, IUpdate value) => Interface.Insert(index, value);*/ +} + +/// Represents the download content of an update. +public class UpdateDownloadContent +{ + internal UpdateDownloadContent(IUpdateDownloadContent content) + { + DownloadUrl = content.DownloadUrl; + IsDeltaCompressedContent = (content as IUpdateDownloadContent2)?.IsDeltaCompressedContent ?? false; + } + + /// Gets the location of the download content on the server that hosts the update. + public string DownloadUrl { get; } + + /// Gets a that indicates whether an update is a binary update or a full-file update. + /// + /// The UpdateDownloadContent object may require you to update the Windows Update Agent (WUA). For more information, see Updating Windows + /// Update Agent. + /// + public bool IsDeltaCompressedContent { get; } +} + +/// Downloads updates from the server. +/// +/// You can create an instance of this object by using the UpdateDownloader class. Use the Microsoft.Update.Downloader program identifier to +/// create the object. +/// +public class UpdateDownloader +{ + private readonly IUpdateDownloader downloader = new(); + + /// Initializes a new instance of the class. + /// The updates to download. + public UpdateDownloader(IEnumerable? updates = null) + { + if (updates is not null) + { + UpdateCollection c = updates.ToCollection(); + downloader.Updates = c.Interface; + } + } + + /// Gets and sets the current client application. + /// Returns the value Unknown if the client application has not set the property. + public string? ClientApplicationID { get => downloader.ClientApplicationID; set => downloader.ClientApplicationID = value; } + + /// + /// Gets and sets a that indicates whether the Windows Update Agent (WUA) forces the download of updates that are + /// already installed or that cannot be installed. + /// + /// This method returns if the object that is implementing the object is locked down. + public bool IsForced { get => downloader.IsForced; set => downloader.IsForced = value; } + + /// Gets and sets the priority level of the download. + public DownloadPriority Priority { get => downloader.Priority; set => downloader.Priority = value; } + + /// Gets and sets an object that contains a read-only collection of the updates that are specified for download. + public IEnumerable Updates { get => new UpdateCollection(downloader.Updates); set => downloader.Updates = value.ToCollection().Interface; } + + /// Starts a synchronous download of the content files that are associated with the updates. + /// A DownloadResult instance that contains result codes for the download. + /// + /// This method returns if the object that is implementing the object is locked down. + /// + /// This method returns if the Updates property of the UpdateDownloader instance is not set. This method + /// also returns if the property is set to an empty collection. + /// + /// This method returns SUS_E_NOT_INITIALIZED if the download job does not contain updates. + /// + public DownloadResult Download() => new(downloader.Download()); + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(downloader, flags); + +#if NET6_0_OR_GREATER + /// Performs an asynchronous download of the content files that are associated with the updates. + /// A callback method that is called periodically for download progress changes before download is complete. + /// + /// The timeout after which the should be faulted with a if it hasn't otherwise completed. + /// + /// The to monitor for a cancellation request. + /// A DownloadResult instance that contains result codes for a download. + /// + /// + /// This method throws a with equal to if the + /// object that is implementing the object is locked down. + /// + /// + /// This method throws a with equal to if the Updates + /// property of the UpdateDownloader instance is not set. This method also throws a with + /// equal to WU_E_NO_UPDATE if the property is set to an empty collection. + /// + /// + /// This method throws a with equal to SUS_E_NOT_INITIALIZED if the + /// download job contains no updates. + /// + /// + public async Task DownloadAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) => + await new DownloadCompletedCallback(downloader).DownloadAsync(onProgressChanged, timeout, cancellationToken); + + private class DownloadCompletedCallback(IUpdateDownloader dl) : IDownloadCompletedCallback, IDownloadProgressChangedCallback + { + private readonly TaskCompletionSource tcs = new(); + private Action? onProgress; + + public async Task DownloadAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + onProgress = onProgressChanged; + dl.BeginDownload(this, this, null); + return await (timeout.HasValue ? tcs.Task.WaitAsync(timeout.Value, cancellationToken) : tcs.Task.WaitAsync(cancellationToken)); + } + + public HRESULT Invoke(IDownloadJob downloadJob, IDownloadProgressChangedCallbackArgs callbackArgs) + { + var prog = callbackArgs.Progress; + onProgress?.Invoke(new(prog)); + if (tcs.Task.IsCanceled) + downloadJob.RequestAbort(); + return HRESULT.S_OK; + } + + public HRESULT Invoke(IDownloadJob downloadJob, IDownloadCompletedCallbackArgs callbackArgs) + { + if (downloadJob.IsCompleted) + { + var res = dl.EndDownload(downloadJob); + tcs.SetResult(new DownloadResult(res)); + } + return HRESULT.S_OK; + } + } +#endif +} + +/// Contains the properties that indicate the status of a download operation for an update. +public class UpdateDownloadResult +{ + private readonly IUpdateDownloadResult res; + + internal UpdateDownloadResult(IUpdateDownloadResult res) => this.res = res; + + /// Gets the exception value, if any, that is raised during the operation on the update. + public HRESULT HResult => res.HResult; + + /// Gets an OperationResultCode enumeration value that specifies the result of an operation on the update. + public OperationResultCode ResultCode => res.ResultCode; +} + +/// +/// Represents info about the aspects of search results returned in the ISearchResult object that were incomplete. For more info, see Remarks. +/// +/// +/// The object is returned as part of the SearchResult.Warnings property when a search succeeds but can't +/// return complete results. For example, Windows Update might not have been able to retrieve all of the update metadata for a given update +/// from the server. In this situation, the search results returned in the ISearchResult object are usable, but they aren't necessarily +/// complete. The properties of the objects that are returned by the SearchResult.Warnings property +/// contain info about the aspects of the search that were incomplete. This info is unlikely to be useful programmatically, but can sometimes +/// be useful for debugging. +/// +public class UpdateException : Exception +{ + internal UpdateException(IUpdateException e) : base(e.Message) + { + HResult = (int)e.HResult; + Context = e.Context; + } + + /// Gets the context of search results. + public UpdateExceptionContext Context { get; } +} + +/// Represents an ordered read-only list of UpdateHistoryEntry instances. +public class UpdateHistory : VirtualReadOnlyList +{ + /// Initializes a new instance of the class. + public UpdateHistory() : this(null) { } + + internal UpdateHistory(IUpdateSearcher? searcher = null) : base(new HistoryMethods(searcher)) + { + } + + private class HistoryMethods(IUpdateSearcher? c) : IVirtualReadOnlyListMethods + { + public readonly IUpdateSearcher src = c ?? new IUpdateSearcher(); + + public int GetItemCount() => src.GetTotalHistoryCount(); + + public bool TryGet(int index, [NotNullWhen(true)] out UpdateHistoryEntry? value) + { + IUpdateHistoryEntry? iupd = index >= 0 && index < GetItemCount() ? src.QueryHistory(index, 1)[0] : null; + value = iupd is not null ? new UpdateHistoryEntry(iupd) : null; + return value is not null; + } + } +} + +/// Represents the recorded history of an update. +public class UpdateHistoryEntry +{ + internal readonly IUpdateHistoryEntry e; + + internal UpdateHistoryEntry(IUpdateHistoryEntry e) => this.e = e; + + /// Gets a collection of the update categories to which an update belongs. + /// + /// + /// The UpdateHistoryEntry instance may require you to update Windows Update Agent (WUA). For more information, see Updating Windows + /// Update Agent. + /// + /// + /// The information that this property returns is for the default user interface (UI) language of the user. If the default UI language of + /// the user is unavailable, WUA uses the default UI language of the computer. If the default language of the computer is unavailable, + /// WUA uses the language that the provider of the update recommends. + /// + /// + /// Because there is a Categories property of the Update instance and a property of the UpdateHistoryEntry + /// object, the information that is used by the localized properties of the Category instance depends on the WUA object that owns the + /// class. If the class is returned from the property of , it follows the localization rules of . If the class is returned from the + /// property of , it follows the localization rules of . + /// + /// + public IReadOnlyCollection Categories => new CategoryCollection((e as IUpdateHistoryEntry2)?.Categories); + + /// Gets the identifier of the client application that processed an update. + /// Returns if the client application has not set the property. + public string ClientApplicationID => e.ClientApplicationID; + + /// Gets the date and the time an update was applied. + public DateTime Date => e.Date; + + /// Gets the description of an update. + /// + /// The information that this property returns is for the default user interface (UI) language of the user. However, note the following: + /// + /// + /// + /// If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI language of the computer. + /// + /// + /// + /// + /// If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// + /// + public string? Description => e.Description; + + /// Gets the value that is returned from the operation on an update. + /// The returned value is a mapped exception code. To retrieve the actual exception code, use the UnmappedResultCode property. + public HRESULT HResult => e.HResult; + + /// Gets an UpdateOperation value that specifies the operation on an update. + public UpdateOperation Operation => e.Operation; + + /// Gets an OperationResultCode value that specifies the result of an operation on an update. + public OperationResultCode ResultCode => e.ResultCode; + + /// Gets the ServerSelection value that indicates which server provided an update. + public ServerSelection ServerSelection => e.ServerSelection; + + /// + /// + /// Gets the service identifier of an update service that is not a Windows update. This property is meaningful only if the + /// ServerSelection property returns ssOthers. + /// + /// + public string? ServiceID => e.ServiceID; + + /// Gets a hyperlink to the language-specific support information for an update. + /// + /// The information that this property returns is for the default user interface (UI) language of the user. However, note the following: + /// + /// + /// + /// If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI language of the computer. + /// + /// + /// + /// + /// If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// + /// + public string SupportUrl => e.SupportUrl; + + /// Gets the title of an update. + /// + /// The information that this property returns is for the default user interface (UI) language of the user. However, note the following: + /// + /// + /// + /// If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI language of the computer. + /// + /// + /// + /// + /// If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// + /// + public string Title => e.Title; + + /// Gets the uninstallation notes of an update. + /// + /// The information that this property returns is for the default user interface (UI) language of the user. However, note the following: + /// + /// + /// + /// If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI language of the computer. + /// + /// + /// + /// + /// If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// + /// + public string? UninstallationNotes => e.UninstallationNotes; + + /// Gets the StringCollection instance that contains the uninstallation steps for an update. + /// + /// The information that this property returns is for the default user interface (UI) language of the user. However, note the following: + /// + /// + /// + /// If the default UI language of the user is unavailable, Windows Update Agent (WUA) uses the default UI language of the computer. + /// + /// + /// + /// + /// If the default language of the computer is unavailable, WUA uses the language that the provider of the update recommends. + /// + /// + /// + /// + public IReadOnlyList UninstallationSteps => new StringCollection(e.UninstallationSteps); + + /// Gets the unmapped result code that is returned from an operation on an update. + /// The returned value is an unmapped result code. To retrieve a mapped exception code, use the HResult property. + public int UnmappedResultCode => e.UnmappedResultCode; + + /// Gets the UpdateIdentity instance that contains the identity of the update. + public UpdateIdentity UpdateIdentity => new(e.UpdateIdentity); +} + +/// Represents the unique identifier of an update. +/// You can create an instance of this object by using the UpdateIdentity class. +public class UpdateIdentity +{ + private readonly IUpdateIdentity id; + + internal UpdateIdentity(IUpdateIdentity id) => this.id = id; + + /// Gets the revision number of the update. + public int RevisionNumber => id.RevisionNumber; + + /// Gets the revision-independent identifier of an update. + public string UpdateID => id.UpdateID; +} + +/// Contains the properties and the methods that are available to the status of an installation or uninstallation of an update. +public class UpdateInstallationResult +{ + private readonly IUpdateInstallationResult res; + + internal UpdateInstallationResult(IUpdateInstallationResult res) => this.res = res; + + /// Gets the exception value that is raised during the operation on an update. + public HRESULT HResult => res.HResult; + + /// + /// Gets a that indicates whether a system restart is required on a computer to complete the installation of an update. + /// + public bool RebootRequired => res.RebootRequired; + + /// Gets an OperationResultCode value that specifies the result of an operation on an update. + public OperationResultCode ResultCode => res.ResultCode; +} + +/// Installs or uninstalls updates from or onto a computer. +/// +/// This object can be instantiated by using the UpdateInstaller class. Use the Microsoft.Update.Installer program identifier to create the object. +/// +public class UpdateInstaller +{ + private readonly IUpdateInstaller inst = new(); + + /// Initializes a new instance of the class. + /// The updates to install. + public UpdateInstaller(IEnumerable? updates = null) + { + if (updates is not null && updates.Any()) + inst.Updates = updates.ToCollection().Interface; + } + + /// Gets and sets a that indicates whether to show source prompts to the user when installing the updates. + [DefaultValue(false)] + public bool AllowSourcePrompts { get => inst.AllowSourcePrompts; set => inst.AllowSourcePrompts = value; } + + /// + /// Gets and sets a value indicating whether the update installer will attempt to close applications, blocking immediate installation of updates. + /// + /// True if the installer will attempt to close applications. + [DefaultValue(false)] + public bool AttemptCloseAppsIfNecessary + { + get => (inst as IUpdateInstaller3)?.AttemptCloseAppsIfNecessary ?? throw new NotImplementedException(); + set { if (inst is IUpdateInstaller3 i3) i3.AttemptCloseAppsIfNecessary = value; else throw new NotImplementedException(); } + } + + /// Gets and sets the current client application. + /// Returns if the client application has not set the property. + [DefaultValue(null)] + public string? ClientApplicationID { get => inst.ClientApplicationID; set => inst.ClientApplicationID = value; } + + /// + /// Gets and sets a that indicates whether Windows Installer is forced to install the updates without user interaction. + /// + /// + /// You cannot forcibly silence some updates. If an update does not support this action, and you try to install the update, the update + /// returns the following: WU_E_UH_DOESNOTSUPPORTACTION. + /// + [DefaultValue(false)] + public bool ForceQuiet + { + get => (inst as IUpdateInstaller2)?.ForceQuiet ?? false; + set { if (inst is IUpdateInstaller2 i) i.ForceQuiet = value; else throw new NotImplementedException(); } + } + + /// + /// Gets a that indicates whether an installation or uninstallation is in progress on a computer at a specific time. + /// + /// + /// A new installation or uninstallation is processed only when no other installation or uninstallation is in progress. While an + /// installation or uninstallation is in progress, a new installation or uninstallation immediately fails with the error. The property does not secure an opportunity for the caller to begin a + /// new installation or uninstallation. If the property or a recent installation or uninstallation failure indicates + /// that another installation or uninstallation is already in progress, the caller should attempt the installation or uninstallation later. + /// + public bool IsBusy => inst.IsBusy; + + /// Gets or sets a that indicates whether to forcibly install or uninstall an update. + /// + /// + /// A forced installation is an installation in which an update is installed even if the metadata indicates that the update is already + /// installed. A forced uninstallation is an uninstallation in which an update is removed even if the metadata indicates that the update + /// is not installed. + /// + /// + /// Before you use to force an installation, determine whether the update is installed and available. If an update + /// is not installed, a forced installation fails. For example, an update can be downloaded, and then its corresponding files removed + /// from the cache after the expiration limit. In this case, if the files are not installed, a forced installation of the update fails. + /// + /// + [DefaultValue(false)] + public bool IsForced { get => inst.IsForced; set => inst.IsForced = value; } + + /// Gets and sets a handle to the parent window that can contain a dialog box. + /// + /// This property can be changed only by a user on the computer. + /// + [DefaultValue(typeof(HWND), "NULL")] + public HWND ParentHwnd { get => inst.ParentHwnd; set => inst.ParentHwnd = value; } + + /// Gets a that indicates whether a system restart is required before installing or uninstalling updates. + public bool RebootRequiredBeforeInstallation => inst.RebootRequiredBeforeInstallation; + + /// Gets and sets an object that contains a read-only collection of the updates that are specified for installation or uninstallation. + public IEnumerable Updates { get => new UpdateCollection(inst.Updates); set => inst.Updates = value.ToCollection().Interface; } +/* + /// Finalizes updates that were previously staged or installed. + /// + /// + /// The API was made public in the 1809 SDK. Any app compiled with the wuapi.h header can use the method on previous versions of Windows 10 as well. + /// + /// + /// should only be called once. This call should happen just prior to commencing a reboot. Calling it multiple times + /// prior to a reboot is not supported and may cause the update to fail. + /// + /// + /// Calling is required prior to rebooting when a feature update is pending reboot. If is not + /// called in this circumstance the update won’t be finalized and installed during the reboot. + /// + /// is safe to call prior to reboot for any other types of updates as well. + /// + // https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdateinstaller4-commit HRESULT Commit( DWORD dwFlags ); + [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(1610874882)] + public void Commit() { if (inst is IUpdateInstaller4 i4) i4.Commit(0); else throw new NotImplementedException(); } +*/ + /// Starts a synchronous installation of the updates. + /// + /// A InstallationResult instance that represents the results of an installation operation for each update that is specified in a request. + /// + /// + /// This method throws a with equal to WU_E_NO_UPDATE if the Updates property of + /// IUpdateInstaller is not set. This method also throws a with equal to WU_E_NO_UPDATE + /// if the property is set to an empty collection. + /// + public InstallationResult Install() => new(inst.Install()); + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(inst, flags); + + /// Starts a wizard that guides the local user through the steps to install the updates. + /// + /// An optional string value to be displayed in the title bar of the wizard. + /// If an empty string value is used, the following text is displayed: Download and Install Updates. + /// + /// + /// A InstallationResult instance that represents the results of an installation operation for each update that is specified in the request. + /// + /// + /// This method throws a with equal to WU_E_NO_UPDATE if the Updates property of + /// IUpdateInstaller is not set. This method also throws a with equal to WU_E_NO_UPDATE + /// if the property is set to an empty collection. + /// + public InstallationResult RunWizard(string dialogTitle = "") => new(inst.RunWizard(dialogTitle)); + + /// Starts a synchronous uninstallation of the updates. + /// + /// A InstallationResult instance that represents the results of an uninstallation operation for each update that is specified in a request. + /// + /// + /// This method throws a with equal to WU_E_NO_UPDATE if the Updates property of + /// IUpdateInstaller is not set. This method also throws a with equal to WU_E_NO_UPDATE + /// if the property is set to an empty collection. + /// + public InstallationResult Uninstall() => new(inst.Uninstall()); + +#if NET6_0_OR_GREATER + /// Starts an asynchronous installation of the updates. + /// + /// A callback method that is called periodically for installation progress changes before the installation is complete. + /// + /// + /// The timeout after which the should be faulted with a if it hasn't otherwise completed. + /// + /// The to monitor for a cancellation request. + /// A InstallationResult instance that represents the overall result of the installation operation. + /// + /// + /// This method throws a with equal to WU_E_NO_UPDATE if the Updates property of + /// IUpdateInstaller is not set. This method also throws a with equal to WU_E_NO_UPDATE + /// if the property is set to an empty collection. + /// + /// + public Task InstallAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + //var cb = new InstallCallback(inst); + //return await cb.InstallAsync(onProgressChanged, timeout, cancellationToken); + var task = new TaskCompletionSource(); + if (cancellationToken.IsCancellationRequested) + { + task.TrySetCanceled(cancellationToken); + return task.Task; + } + IInstallationJob? job = null; + CancellationTokenRegistration? reg = null; + job = inst.BeginInstall(new InstallationProgressChangeCallback(onProgressChanged), new InstallationCompletedCallback(OnComplete), null); + reg = cancellationToken.Register(() => + { + task.TrySetCanceled(cancellationToken); + job?.RequestAbort(); + }); + return task.Task; + + void OnComplete(IInstallationJob _job2) + { + try + { + try { task.TrySetResult(new(inst.EndInstall(_job2))); } + catch (Exception e) { task.TrySetException(e); } + } + finally + { + job = null; + reg?.Dispose(); + } + } + } + + /// Starts an asynchronous uninstallation of the updates. + /// + /// A callback method that is called periodically for uninstallation progress changes before the uninstallation is complete. + /// + /// + /// The timeout after which the should be faulted with a if it hasn't otherwise completed. + /// + /// The to monitor for a cancellation request. + /// A InstallationResult instance that represents the overall result of an uninstallation operation. + /// + /// + /// This method throws a with equal to WU_E_NO_UPDATE if the Updates property of + /// IUpdateInstaller is not set. This method also throws a with equal to WU_E_NO_UPDATE + /// if the property is set to an empty collection. + /// + /// + public async Task UninstallAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) => + await new InstallCallback(inst).UninstallAsync(onProgressChanged, timeout, cancellationToken); + + internal class InstallationProgressChangeCallback(Action? Action) : IInstallationProgressChangedCallback + { + HRESULT IInstallationProgressChangedCallback.Invoke([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, + [In, MarshalAs(UnmanagedType.Interface)] IInstallationProgressChangedCallbackArgs callbackArgs) + { try { Action?.Invoke(new(callbackArgs.Progress)); } catch (Exception ex) { return ex.HResult; } return HRESULT.S_OK; } + } + internal class InstallationCompletedCallback(Action Action) : IInstallationCompletedCallback + { + HRESULT IInstallationCompletedCallback.Invoke([In, MarshalAs(UnmanagedType.Interface)] IInstallationJob installationJob, + [In, MarshalAs(UnmanagedType.Interface)] IInstallationCompletedCallbackArgs? callbackArgs) + { try { Action?.Invoke(installationJob); } catch (Exception ex) { return ex.HResult; } return HRESULT.S_OK; } + } + + [ComVisible(true)] + private class InstallCallback(IUpdateInstaller installer) : IInstallationCompletedCallback, IInstallationProgressChangedCallback + { + private readonly TaskCompletionSource tcs = new(); + private Action? onProgress; + + public Task InstallAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + if (cancellationToken.IsCancellationRequested) + { + tcs.TrySetCanceled(cancellationToken); + return tcs.Task; + } + onProgress = onProgressChanged; + var job = installer.BeginInstall(this, this, null); + cancellationToken.Register(() => { tcs.TrySetCanceled(cancellationToken); job!.RequestAbort(); }); + return (timeout.HasValue ? tcs.Task.WaitAsync(timeout.Value, cancellationToken) : tcs.Task.WaitAsync(cancellationToken)); + } + + public async Task UninstallAsync(Action? onProgressChanged, TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + onProgress = onProgressChanged; + installer.BeginUninstall(this, this, 0); + return await (timeout.HasValue ? tcs.Task.WaitAsync(timeout.Value, cancellationToken) : tcs.Task.WaitAsync(cancellationToken)); + } + + HRESULT IInstallationCompletedCallback.Invoke(IInstallationJob installationJob, IInstallationCompletedCallbackArgs? callbackArgs) + { + if (installationJob.IsCompleted) + { + var res = installationJob.AsyncState is int i && i == 0 ? installer.EndUninstall(installationJob) : installer.EndInstall(installationJob); + try { tcs.TrySetResult(new InstallationResult(res)); } + catch (Exception e) { tcs.TrySetException(e); } + } + return HRESULT.S_OK; + } + + HRESULT IInstallationProgressChangedCallback.Invoke(IInstallationJob installationJob, IInstallationProgressChangedCallbackArgs callbackArgs) + { + IInstallationProgress prog = callbackArgs.Progress; + onProgress?.Invoke(new(prog)); + if (tcs.Task.IsCanceled) + installationJob.RequestAbort(); + return HRESULT.S_OK; + } + } +#endif +} + +/// Searches for updates on a server. +/// +/// You can create an instance of this object by using the UpdateSearcher class. Use the Microsoft.Update.Searcher program identifier to +/// create the object. +/// +public partial class UpdateSearcher +{ + private readonly IUpdateSearcher searcher = new IUpdateSession().CreateUpdateSearcher(); + + /// + /// + /// Gets and sets a that indicates whether future calls to the BeginSearch and Search methods result in an automatic + /// upgrade to Windows Update Agent (WUA). Currently, this property's valid value corresponds to the option that does not automatically + /// upgrade WUA. + /// + /// + public bool CanAutomaticallyUpgradeService { get => searcher.CanAutomaticallyUpgradeService; set => searcher.CanAutomaticallyUpgradeService = value; } + + /// Identifies the current client application. + /// Returns if the client application has not set the property. + public string ClientApplicationID { get => searcher.ClientApplicationID; set => searcher.ClientApplicationID = value; } + + /// + /// + /// Gets and sets a that indicates whether to ignore the download priority. The download priority determines whether + /// one update should replace another update. + /// + /// + /// + /// The UpdateSearcher instance may require you to update Windows Update Agent (WUA). For more information, see Updating Windows Update Agent. + /// + public bool IgnoreDownloadPriority + { + get => (searcher as IUpdateSearcher2)?.IgnoreDownloadPriority ?? throw new NotImplementedException(); + set { if (searcher is IUpdateSearcher2 s2) s2.IgnoreDownloadPriority = value; else throw new NotImplementedException(); } + } + + /// + /// + /// Gets and sets a that indicates whether the search results include updates that are superseded by other updates in + /// the search results. + /// + /// + /// Note + /// This property is no longer supported in Windows 10, version 1709 (build 16299), and later OS releases. + /// + /// + public bool IncludePotentiallySupersededUpdates { get => searcher.IncludePotentiallySupersededUpdates; set => searcher.IncludePotentiallySupersededUpdates = value; } + + /// Gets and sets a that indicates whether the UpdateSearcher goes online to search for updates. + public bool Online { get => searcher.Online; set => searcher.Online = value; } + + /// Synchronously queries the computer for the history of the update events. + /// + /// A pointer to a UpdateHistoryEntryCollection instance that contains matching event records on the computer in descending chronological order. + /// + public UpdateHistory QueryHistory => new(searcher); + + /// Gets or sets the search scope. + /// The search scope. + public SearchScope SearchScope + { + get => (searcher as IUpdateSearcher3)?.SearchScope ?? throw new NotImplementedException(); + set { if (searcher is IUpdateSearcher3 s3) s3.SearchScope = value; else throw new NotImplementedException(); } + } + + /// Gets and sets a ServerSelection value that indicates the server to search for updates. + /// + /// The site that is not a Windows Update site that is specified by the value of the ServiceID property is searched only if the value of + /// the property is ssOthers. + /// + public ServerSelection ServerSelection { get => searcher.ServerSelection; set => searcher.ServerSelection = value; } + + /// Gets and sets a site to search when the site to search is not a Windows Update site. + /// + /// The site that is not a Windows Update site that is specified by the value of the property is searched only if + /// the value of the ServerSelection property is ssOthers. + /// + public string? ServiceID { get => searcher.ServiceID; set => searcher.ServiceID = value; } + + /// Initiates a fluent query for filtering updates based on their properties. + public QueryCondition Where => new(this); + + /// Converts a string into a string that can be used as a literal value in a search criteria string. + /// A string to be escaped. + /// The resulting escaped string. + public string? GetEscapedString(string? unescaped) => searcher.EscapeString(unescaped); + + /// Performs a synchronous search for updates. The search uses the search options that are currently configured. + /// A string that specifies the search criteria. + /// + /// A SearchResult instance that contains the following: + /// + /// + /// The result of an operation + /// + /// + /// A collection of updates that match the search criteria + /// + /// + /// + /// + /// + /// The string that is used for the parameter must match the custom search language for the + /// method. The string consists of criteria that are evaluated to determine the updates to return. + /// + /// + /// Each criterion specifies an update property name and value. With some restrictions, multiple criteria can be connected with the + /// and and or operators. The = (equal) and != (not-equal) operators are both supported. When you use Windows + /// Update Agent (WUA), the != (not-equal) operator can be used only with the type criterion. + /// + /// + /// The search criteria syntax is based on the WHERE clause of an SQL query expression. Most of the supported criteria map directly to + /// update properties. These update properties resemble the elements in a virtual XML document that contains the entire server catalog. + /// For example, if you specify a search criteria string of "AutoSelectOnWebSites = 1", the search returns all the updates that have a + /// AutoSelectOnWebSites property with a value of . + /// + /// + /// A single criterion consists of " Name = Value" or " Name != Value", where " Name" is one of the + /// supported criterion names, and " Value" is a string or an integer. The and and or operators can be used to + /// connect multiple criteria. However, or can be used only at the top level of the search criteria. Therefore, "(x=1 and y=1) or + /// (z=1)" is valid, but "(x=1) and (y=1 or z=1)" is not valid. + /// + /// + /// The supported value types are integers and strings. An integer must be specified in base 10, and negative numbers are prefixed with a + /// minus sign ( -). A string must be escaped and enclosed in single quotation marks ('). All string comparisons are + /// case-insensitive unless specified. + /// + /// + /// The following table identifies all the public support criteria in the order of evaluation precedence. More criteria may be added to + /// this list in the future. + /// + /// + /// + /// Criterion + /// Type + /// Allowed operators + /// Description + /// + /// + /// Type + /// + /// =, != + /// Finds updates of a specific type, such as "'Driver'" and "'Software'". + /// + /// + /// DeploymentAction + /// + /// = + /// + /// Finds updates that are deployed for a specific action, such as an installation or uninstallation that the administrator of a server + /// specifies. "DeploymentAction='Installation'" finds updates that are deployed for installation on a destination computer. + /// "DeploymentAction='Uninstallation'" depends on the other query criteria. "DeploymentAction='Uninstallation'" finds updates that are + /// deployed for uninstallation on a destination computer. "DeploymentAction='Uninstallation'" depends on the other query criteria. If + /// this criterion is not explicitly specified, each group of criteria that is joined to an and operator implies "DeploymentAction='Installation'". + /// + /// + /// + /// IsAssigned + /// int(bool) + /// = + /// + /// Finds updates that are intended for deployment by Automatic Updates. "IsAssigned=1" finds updates that are intended for deployment by + /// Automatic Updates, which depends on the other query criteria. At most, one assigned Windows-based driver update is returned for each + /// local device on a destination computer. "IsAssigned=0" finds updates that are not intended to be deployed by Automatic Updates. + /// + /// + /// + /// BrowseOnly + /// int(bool) + /// = + /// + /// "BrowseOnly=1" finds updates that are considered optional. "BrowseOnly=0" finds updates that are not considered optional. + /// + /// + /// + /// AutoSelectOnWebSites + /// int(bool) + /// = + /// + /// Finds updates where the AutoSelectOnWebSites property has the specified value. "AutoSelectOnWebSites=1" finds updates that are + /// flagged to be automatically selected by Windows Update. "AutoSelectOnWebSites=0" finds updates that are not flagged for Automatic Updates. + /// + /// + /// + /// UpdateID + /// string(UUID) + /// =, != + /// + /// Finds updates for which the value of the UpdateIdentity.UpdateID property matches the specified value. Can be used with the != + /// operator to find all the updates that do not have an UpdateIdentity.UpdateID of the specified value. For example, + /// "UpdateID='12345678-9abc-def0-1234-56789abcdef0'" finds updates for UpdateIdentity.UpdateID that equal + /// 12345678-9abc-def0-1234-56789abcdef0. For example, "UpdateID!='12345678-9abc-def0-1234-56789abcdef0'" finds updates for + /// UpdateIdentity.UpdateID that are not equal to 12345678-9abc-def0-1234-56789abcdef0. For example, + /// "UpdateID='12345678-9abc-def0-1234-56789abcdef0' and RevisionNumber=100" can be used to find the update for UpdateIdentity.UpdateID + /// that equals 12345678-9abc-def0-1234-56789abcdef0 and whose UpdateIdentity.RevisionNumber equals 100. + /// + /// + /// + /// RevisionNumber + /// + /// = + /// + /// Finds updates for which the value of the UpdateIdentity.RevisionNumber property matches the specified value. For example, + /// "RevisionNumber=2" finds updates where UpdateIdentity.RevisionNumber equals 2. This criterion must be combined with the UpdateID property. + /// + /// + /// + /// CategoryIDs + /// string(uuid) + /// contains + /// Finds updates that belong to a specified category. + /// + /// + /// IsInstalled + /// int(bool) + /// = + /// + /// Finds updates that are installed on the destination computer. "IsInstalled=1" finds updates that are installed on the destination + /// computer. "IsInstalled=0" finds updates that are not installed on the destination computer. + /// + /// + /// + /// IsHidden + /// int(bool) + /// = + /// + /// Finds updates that are marked as hidden on the destination computer. "IsHidden=1" finds updates that are marked as hidden on a + /// destination computer. When you use this clause, you can set the UpdateSearcher.IncludePotentiallySupersededUpdates property to so that a search returns the hidden updates. The hidden updates might be superseded by other updates in the same + /// results. "IsHidden=0" finds updates that are not marked as hidden. If the UpdateSearcher.IncludePotentiallySupersededUpdates property + /// is set to , it is better to include that clause in the search filter string so that the updates that are + /// superseded by hidden updates are included in the search results. is the default value. + /// + /// + /// + /// IsPresent + /// int(bool) + /// = + /// + /// When set to 1, finds updates that are present on a computer. "IsPresent=1" finds updates that are present on a destination computer. + /// If the update is valid for one or more products, the update is considered present if it is installed for one or more of the products. + /// "IsPresent=0" finds updates that are not installed for any product on a destination computer. + /// + /// + /// + /// RebootRequired + /// int(bool) + /// = + /// + /// Finds updates that require a computer to be restarted to complete an installation or uninstallation. "RebootRequired=1" finds updates + /// that require a computer to be restarted to complete an installation or uninstallation. "RebootRequired=0" finds updates that do not + /// require a computer to be restarted to complete an installation or uninstallation. + /// + /// + /// + /// The default search criteria for a search are as follows: + /// + /// To find all the hidden updates (by using the UpdateSearcher.IncludePotentiallySupersededUpdates property set to ), use the following criterion: + /// + /// + public SearchResult Search(string criteria = "") => new(searcher.Search(criteria)); + +#if NET6_0_OR_GREATER + /// Begins execution of an asynchronous search for updates. The search uses the search options that are currently configured. + /// A string that specifies the search criteria. + /// + /// The timeout after which the should be faulted with a if it hasn't otherwise completed. + /// + /// The to monitor for a cancellation request. + /// + /// A SearchResult instance that contains the following: + /// + /// + /// The result of an operation + /// + /// + /// A collection of updates that match the search criteria + /// + /// + /// + /// + /// For a complete description of search criteria syntax, see Search. + /// + public async Task SearchAsync(string criteria = "", TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + var cb = new SearchCompletedCallback(searcher); + return await cb.SearchAsync(criteria, timeout, cancellationToken); + } + + private class SearchCompletedCallback(IUpdateSearcher searcher) : ISearchCompletedCallback + { + private readonly TaskCompletionSource tcs = new(); + + public async Task SearchAsync(string criteria, TimeSpan? timeout = null, CancellationToken cancellationToken = default) + { + searcher.BeginSearch(criteria, this, 0); + return await (timeout.HasValue ? tcs.Task.WaitAsync(timeout.Value, cancellationToken) : tcs.Task.WaitAsync(cancellationToken)); + } + + HRESULT ISearchCompletedCallback.Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) + { + if (searchJob.IsCompleted) + { + var res = searcher.EndSearch(searchJob); + tcs.SetResult(new SearchResult(res)); + } + return HRESULT.S_OK; + } + } +#endif +} + +/// Contains information about a service that is registered with Windows Update Agent (WUA) or with Automatic Updates. +public class UpdateService +{ + internal readonly IUpdateService svc; + internal IUpdateServiceRegistration? reg = null; + + internal UpdateService(IUpdateService svc) => this.svc = svc ?? throw new ArgumentNullException(nameof(svc)); + + /// Gets a that indicates whether the service can register with Automatic Updates. + public bool CanRegisterWithAU => svc.CanRegisterWithAU; + + /// Gets an SHA-1 hash of the certificate that is used to sign the contents of the service. + public byte[]? ContentValidationCert => (byte[]?)svc.ContentValidationCert; + + /// + /// Gets a that indicates whether the service is registered with Automatic Updates and whether the service is + /// currently used by Automatic Updates as the default service. + /// + public bool? IsDefaultAUService => (svc as IUpdateService2)?.IsDefaultAUService; + + /// Gets a that indicates whether a service is a managed service. + public bool IsManaged => svc.IsManaged; + + /// + /// Gets a that indicates whether the service will also be registered with Automatic Updates, when added. The + /// authorization cabinet file (.cab) of the service determines whether the service can be added. + /// + /// + /// If the RegistrationState property is , registration with Automatic Updates is subject to the + /// allowed settings that are specified in the authorization cabinet file (.cab) for the service. If the authorization cabinet file does + /// not allow registration with Automatic Updates, the service will be registered with Windows Update Agent (WUA). However, the service + /// will not be registered with Automatic Updates. + /// + public bool IsPendingRegistrationWithAU => Reg.IsPendingRegistrationWithAU; + + /// Gets a that indicates whether a service is registered with Automatic Updates. + public bool IsRegisteredWithAU => svc.IsRegisteredWithAU; + + /// Gets a that indicates whether a service is based on a scan package. + public bool IsScanPackageService => svc.IsScanPackageService; + + /// Gets the date on which the authorization cabinet file was issued. + public DateTime IssueDate => svc.IssueDate; + + /// Gets the name of the service. + /// + /// The localized properties of an update are returned in the language that corresponds to the user default user interface (UI) language + /// of the caller. If a property of an update is unavailable in such language, it will be returned in the system default UI language on + /// the specified computer. If the property is unavailable in either languages mentioned, then it will be returned in the language + /// recommended, if any, by the provider of the Update. Otherwise the Update Service will choose a language as it sees fit for the property. + /// + public string? Name => svc.Name; + + /// Gets a indicates whether the current service offers updates from Windows Updates. + public bool OffersWindowsUpdates => svc.OffersWindowsUpdates; + + /// The property contains the URLs for the redirector cabinet file. + public IReadOnlyList RedirectUrls => new StringCollection(svc.RedirectUrls); + + /// Gets an UpdateServiceRegistrationState value that indicates the current state of the service registration. + public UpdateServiceRegistrationState RegistrationState => Reg.RegistrationState; + + /// The property retrieves or sets the identifier for a service. + public string ServiceID => svc.ServiceID; + + /// The property retrieves the URL for the service. + public string? ServiceUrl => svc.ServiceUrl; + + /// The property identifies the prefix for the setup files. + public string? SetupPrefix => svc.SetupPrefix; + + private IUpdateServiceRegistration Reg => reg ??= new IUpdateServiceManager2().QueryServiceRegistration(ServiceID); +} + +/// Adds or removes the registration of the update service with Windows Update Agent or Automatic Updates. +/// +/// You can create an instance of this object by using the UpdateServiceManager class. Use the Microsoft.Update.ServiceManager program +/// identifier to create the object. +/// +public class UpdateServiceManager : IReadOnlyList +{ + private readonly IUpdateServiceManager mgr = new(); + + /// Gets and sets the identifier of the current client application. + /// Returns if the client application has not set the property. + public string? ClientApplicationID + { + get => (mgr as IUpdateServiceManager2)?.ClientApplicationID; + set { if (mgr is IUpdateServiceManager2 m2) m2.ClientApplicationID = value; else throw new NotImplementedException(nameof(ClientApplicationID)); } + } + + /// + public int Count => mgr.Services.Count; + + /// + public UpdateService this[int index] => index < 0 || index >= Count ? throw new ArgumentOutOfRangeException(nameof(index)) : new(mgr.Services[index]); + + /// Gets the with the specified service identifier. + /// The service identifier of a registered service. + /// The resulting instance. + /// id + public UpdateService this[string id] + { + get + { + var res = mgr.Services.Cast().FirstOrDefault(s => s.ServiceID == id); + return res is not null ? new(res) : throw new ArgumentOutOfRangeException(nameof(id)); + } + } + + /// Registers a scan package as a service with Windows Update Agent (WUA) and then returns a UpdateService instance. + /// A descriptive name for the scan package service. + /// The path of the Microsoft signed scan file that has to be registered as a service. + /// A pointer to a UpdateService instance that contains service registration information. + /// + /// You can use the ID of the service in searches by passing the ID as the ServiceID property of the UpdateSearcher instance. + /// To free resources, remove the service after it is no longer needed. Use the RemoveService method to remove the service. + /// Do not call the RegisterServiceWithAU method for the service that the method registers. + /// + /// The service that is returned by is in the collection of services that the Services property of + /// the UpdateServiceManager instance returns. This service has the special IsScanPackageService property. + /// + /// An error is returned by WinVerifyTrust if the Authorization Cab is not signed. + /// This method returns if the object that implements the object has been locked down. + /// + public UpdateService AddScanPackageService(string serviceName, string scanFileLocation) => + mgr is IUpdateServiceManager2 mgr2 + ? (UpdateService)new(mgr2.AddScanPackageService(serviceName, scanFileLocation)) + : throw new NotImplementedException(); + + /// + /// Registers a service with Windows Update Agent (WUA) without requiring an authorization cabinet file (.cab). This method also returns + /// a pointer to a UpdateServiceRegistration instance. + /// + /// An identifier for the service to be registered. + /// + /// A combination of AddServiceFlag values that are combined by using a bitwise OR operation. The resulting value specifies options for + /// service registration. For more info, see Remarks. + /// + /// + /// The path of the Microsoft signed local cabinet file (.cab) that has the information that is required for a service registration. If + /// empty, the update agent searches for the authorization cabinet file (.cab) during service registration when a network connection is available. + /// + /// A pointer to a UpdateServiceRegistration instance that represents an added service. + /// + /// This method may return networking error codes when the flag is specified. + /// + /// The parameter is optional for this method. If the parameter is + /// not specified, it will be retrieved from the Windows Update server. + /// + /// + /// This method returns if the or flags are specified and if the value of the parameter is not + /// an empty string. + /// + /// + /// This method returns if the requested change in the state of Automatic Updates is contrary to + /// the specifications in the authorization cabinet file (.cab) when the flag is specified. An + /// error is returned by the WinVerifyTrust function if the authorization cabinet file has not been signed. + /// + /// + /// The update agent and behave in the following ways depending on the AddServiceFlag values that you specify + /// in the parameter: + /// + /// + /// + /// + /// If you specify without , the update agent + /// immediately attempts to go online to register the service. returns an HRESULT value that reflects the + /// success or failure of the registration. If the registration fails, the update agent makes no future attempts to register the service. + /// + /// + /// + /// + /// If you specify without , the update agent doesn't + /// register the service immediately. returns S_OK to indicate that the update agent will attempt to register + /// the service at a later time, which doesn't guarantee that the registration will eventually succeed. + /// + /// + /// + /// + /// If you specify and together, the update agent + /// immediately attempts to go online to register the service. returns S_OK if the registration succeeds. returns a failure HRESULT value if the registration fails, but the update agent still attempts to register the + /// service at a later time. + /// + /// + /// + /// + /// If you specify , , or both, also specify for the parameter. + /// + /// + /// + /// + /// If you specify neither nor (in other words, if + /// is either zero or ), you must specify a non- + /// path in the parameter. In this mode, processes the cabinet file (.cab) + /// and registers the service in the same way as UpdateServiceManager.AddService. + /// + /// + /// + /// + /// If you specify , the change to the default Automatic Updates service doesn't occur (and isn't + /// reflected in the Windows Update user interface) until the service registration succeeds. This means that if the registration succeeds + /// immediately (because you specified or supplied a cabinet file (.cab)), the Automatic + /// Updates service change also occurs immediately. If the registration doesn't succeed until later (because you specified ), the Automatic Updates service change doesn't occur unless the pending service registration + /// eventually succeeds. + /// + /// + /// + /// + public UpdateService? AddService(string serviceID, AddServiceFlag flags = AddServiceFlag.asfAllowOnlineRegistration, string authorizationCabPath = "") + { + if (mgr is IUpdateServiceManager2 mgr2) + { + var ret = mgr2.AddService2(serviceID, flags, authorizationCabPath); + return ret.Service is null ? null : new(ret.Service); + } + var ius = mgr.AddService(serviceID, authorizationCabPath); + if (flags.IsFlagSet(AddServiceFlag.asfRegisterServiceWithAU)) + RegisterServiceWithAU(serviceID); + return new UpdateService(ius); + } + + /// + public IEnumerator GetEnumerator() => mgr.Services.Cast().Select(s => new UpdateService(s)).GetEnumerator(); + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(mgr, flags); + + /// Registers a service with Automatic Updates. + /// An identifier for the service to be registered. + /// + /// This method returns if the service to be registered is unknown to Automatic Updates. + /// + /// This method returns if the method is called with an invalid service ID. This method also returns + /// if the service ID is valid but the service can't register with Automatic Updates. That is, the + /// requested change in the state of Automatic Updates is contrary to the specifications in the authorization cabinet file (for example, + /// CanRegisterWithAU property is set to ). An error is returned by WinVerifyTrust function if the authorization + /// cabinet file has not been signed. + /// + /// This method returns if you try to remove the Windows Update service. + /// + public void RegisterServiceWithAU(string serviceID) => mgr.RegisterServiceWithAU(serviceID); + + /// Removes a service registration from Windows Update Agent (WUA). + /// An identifier for the service to be unregistered. + public void RemoveService(string serviceID) => mgr.RemoveService(serviceID); + + /// + /// Set options for the object that specifies the service ID. The method is also used to determine whether a + /// warning is displayed when you change the registration of Automatic Updates. + /// + /// + /// Set this parameter to AllowedServiceID to specify the form of the service ID that is provided to the object. + /// Set to AllowWarningUI to display a warning when changing the Automatic Updates registration. + /// + /// + /// + /// If the parameter is set to AllowServiceID, the parameter is set to the service ID + /// that is provided as a value. + /// + /// + /// If is set to AllowWarningUI, is a value that specifies + /// whether to display a warning when changing the registration of Automatic Updates. + /// + /// + /// Set the optionValue parameter to to display the warning UI. Set it to to suppress the + /// warning UI. + /// + /// + public void SetOption(string optionName, object optionValue) => mgr.SetOption(optionName, optionValue); + + /// Unregisters a service with Automatic Updates. + /// An identifier for the service to be unregistered. + /// + /// + /// This method returns if the requested change in the state of Automatic Updates is contrary to + /// the specifications in the Authorization Cab. An error is returned by WinVerifyTrust function if the Authorization Cab has not been signed. + /// + /// This method returns if the service to be removed does not exist. + /// + /// This method returns if you attempt to remove the Windows Update service and if it is the + /// only service that is registered with Automatic Updates. + /// + /// + public void UnregisterServiceWithAU(string serviceID) => mgr.UnregisterServiceWithAU(serviceID); + + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); +} + +/// +/// Contains the HTTP proxy settings. +/// Important This object is not supported on Windows 10 and Windows Server 2016. See the remarks for more details. +/// +/// +/// +/// You can create an instance of this object by using the WebProxy class. Use the Microsoft.Update.WebProxy program identifier to create the object. +/// +/// +/// This object is not supported on Windows 10 and Windows Server 2016. To configure proxy settings on these +/// operating systems (including proxy settings for Windows Update Agent), use the Proxy page of the Network & +/// Internet section in Settings. You can optionally use a proxy auto-config script to apply settings. If you configure +/// proxy settings, be sure to allow access to the domains used by Windows Update listed in this article. +/// +/// +public class WebProxy +{ + internal readonly IWebProxy Interface; + + /// Initializes a new instance of the class. + public WebProxy() : this(null) + { + } + + internal WebProxy(IWebProxy? wp) => this.Interface = wp ?? new(); + + /// Gets and sets the address and the decimal port number of the proxy server. + /// + /// The value of the property is ignored if the value of the AutoDetect property is set to . + /// When is a null reference (for example, if you specified Nothing in Visual Basic), all the requests bypass the + /// proxy. The requests connect directly to the destination host. + /// + public string? Address { get => Interface.Address; set => Interface.Address = value; } + + /// Gets and sets a that indicates whether IWebProxy automatically detects proxy settings. + /// + /// The values of the Address, BypassList, and BypassProxyOnLocal properties are ignored if the value of the + /// property is set to . + /// + public bool AutoDetect { get => Interface.AutoDetect; set => Interface.AutoDetect = value; } + + /// Gets and sets a collection of addresses that do not use the proxy server. + /// + /// The value of the property is ignored if the value of the AutoDetect property is set to . + /// + public IList BypassList { get => new StringCollection(Interface.BypassList); set => Interface.BypassList = new StringCollection(value).Interface; } + + /// Gets and sets a that indicates whether local addresses bypass the proxy server. + /// + /// The value of the property is ignored if the value of the AutoDetect property is set to . + /// + public bool BypassProxyOnLocal { get => Interface.BypassProxyOnLocal; set => Interface.BypassProxyOnLocal = value; } + + /// Gets a that indicates whether the WebProxy object is read-only. + public bool ReadOnly => Interface.ReadOnly; + + /// Gets and sets the user name to submit to the proxy server for authentication. + public string? UserName { get => Interface.UserName; set => Interface.UserName = value; } + + /// Restricts access to the methods and properties of the object that implements this method. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public void LockDown([In] UpdateLockdownOption flags) => UpdateLockdown.LockDown(Interface, flags); + + /// Prompts the user for the password to use for proxy authentication. + /// The parent window of the dialog box in which the user enters the credentials. + /// The title to use for the dialog box in which the user enters the credentials. + /// + /// This method can be changed only by a user on the computer. This method can be accessed through the Dispatch instance. + /// + /// If null is specified for the parent window (for example, if you specified Nothing in Visual Basic), the dialog box is displayed on + /// the desktop. + /// + /// + public void PromptForCredentials([In, Optional] HWND parentWindow, string? title) => Interface.PromptForCredentialsFromHwnd(parentWindow, title ?? ""); + + /// Sets the password to submit to the proxy server for authentication. + /// The password to submit to the proxy server for authentication. + public void SetPassword(string? value) => Interface.SetPassword(value); +} + +/// Contains the properties and the methods that are available only from a Windows driver update. +/// +/// This object can be obtained by calling the QueryInterface method on a Update instance only if the object represents a Windows driver update. +/// +public class WindowsDriverUpdate : Update +{ + private readonly IWindowsDriverUpdate Interface; + + internal WindowsDriverUpdate(IWindowsDriverUpdate upd) : base(upd) => Interface = upd; + + /// Gets the problem number of the matching device for the Windows driver update. + public int DeviceProblemNumber => Interface.DeviceProblemNumber; + + /// Gets the status of the matching device for the Windows driver update. + public int DeviceStatus => Interface.DeviceStatus; + + /// Gets the class of the Windows driver update. + public string? DriverClass => Interface.DriverClass; + + /// Gets the hardware ID or compatible ID that the Windows driver update must match to be installable. + public string? DriverHardwareID => Interface.DriverHardwareID; + + /// Gets the language-invariant name of the manufacturer of the Windows driver update. + public string? DriverManufacturer => Interface.DriverManufacturer; + + /// Gets the language-invariant model name of the device for which the Windows driver update is intended. + public string? DriverModel => Interface.DriverModel; + + /// Gets the language-invariant name of the provider of the Windows driver update. + public string? DriverProvider => Interface.DriverProvider; + + /// Gets the driver version date of the Windows driver update. + public DateTime DriverVerDate => Interface.DriverVerDate; + + /// Gets the driver update entries that are applicable for the update. + public IReadOnlyList WindowsDriverUpdateEntries => (Interface as IWindowsDriverUpdate4)?.WindowsDriverUpdateEntries.GetList() ?? []; +} + +/// Contains the properties that are available only from a Windows driver update. +/// +/// None of the WindowsDriverUpdateEntry properties are expected to return any errors (other than E_POINTER if +/// is passed to the property). +/// +public class WindowsDriverUpdateEntry +{ + private readonly IWindowsDriverUpdateEntry entry; + + internal WindowsDriverUpdateEntry(IWindowsDriverUpdateEntry entry) => this.entry = entry; + + /// Gets the problem number of the matching device for the Windows driver update. + public int DeviceProblemNumber => entry.DeviceProblemNumber; + + /// Gets the status of the matching device for the Windows driver update. + public int DeviceStatus => entry.DeviceStatus; + + /// The property retrieves the class of the Windows driver update. + public string? DriverClass => entry.DriverClass; + + /// Gets the hardware or the compatible identifier that the Windows driver update must match to be installable. + public string? DriverHardwareID => entry.DriverHardwareID; + + /// Gets the language-invariant name of the manufacturer of the Windows driver update. + public string? DriverManufacturer => entry.DriverManufacturer; + + /// Gets the language-invariant model name of the device for which the Windows driver update is intended. + public string? DriverModel => entry.DriverModel; + + /// Gets the language-invariant name of the provider of the Windows driver update. + public string? DriverProvider => entry.DriverProvider; + + /// Gets the driver version date of the Windows driver update. + public DateTime DriverVerDate => entry.DriverVerDate; +} + +/// Retrieves information about the version of Windows Update Agent (WUA). +/// +/// +/// The class may require you to update WUA. For more information, see Updating Windows Update Agent. +/// +/// +/// You can create an instance of this object by using the WindowsUpdateAgentInfo class. Use the Microsoft.Update.AgentInfo program +/// identifier to create the object. +/// +/// +public class WindowsUpdateAgentInfo +{ + private readonly IWindowsUpdateAgentInfo wuai = new(); + + /// Retrieves the current version of WUA. + /// + /// The major version is incremented one time for each release if a change occurs in the interfaces of the WUA API. The minor version is + /// incremented one time for each release if a change occurs in the existing interfaces of the WUA API. + /// + public Version ApiVersion => new((int)wuai.GetInfo("ApiMajorVersion"), (int)wuai.GetInfo("ApiMinorVersion")); + + /// Retrieves the file version of the Wuapi.dll file. + public Version ProductVersion => new((string)wuai.GetInfo("ProductVersionString")); +} + +/// Extension methods for Windows Update classes. +public static class Ext +{ + /// Converts enumerated list of to and instance. + /// The items. + /// An instance containing . + public static UpdateCollection ToCollection(this IEnumerable items) => (items as UpdateCollection) ?? new(items); +} + +internal static class IntExt +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static IReadOnlyList GetList(this IEnumerable l) => l.Cast().Select(e => (TOut)Activator.CreateInstance(typeof(TOut), e)!).ToList(); +} + +/// Restricts access to methods and properties of objects that implements the method of this object. +internal static class UpdateLockdown +{ + /// Restricts access to the methods and properties of the object that implements this method. + /// An object that supports IUpdateLockdown. + /// + /// The option to restrict access to various Windows Update Agent (WUA) objects from the Windows Update website. + /// + /// Setting this parameter to or to 1 (one) restricts access to the WUA classes that implement the + /// UpdateLockdown instance. + /// + /// + public static void LockDown(object lockdown, [In] UpdateLockdownOption flags) => (lockdown as IUpdateLockdown ?? throw new NotImplementedException()).LockDown(flags); +} \ No newline at end of file