2022年5月8日 星期日

[研究][C#]呼叫 Windows Update 更新和 Reboot

[研究][C#]呼叫 Windows Update 更新和 Reboot

2022-05-08, 2022-06-07

環境:Visual Studio 2022 + WinForm + Console + C#

********************************************************************************

Program.cs

using System;
/*
WUApiLib 安裝:
(1)在專案的「參考」按下滑鼠右鍵,選「加入參考」,按下「瀏覽」按鈕,
   找到 C:\windows\System32 目錄的wuapi.dll檔案,按下「加入」按鈕。
(2)在「方案總管」點選「(專案)/參考/WUApiLib」,把「內崁Interop類型」從 true 改為 false。
*/
using WUApiLib;

namespace WindowsUpdateAndRebootConsoleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Windows Updates Searching ...");
            UpdateSessionClass uSession = new UpdateSessionClass();
            IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
            ISearchResult uResult = uSearcher.Search("IsInstalled=0 and Type = 'Software'");
            foreach (IUpdate update in uResult.Updates)
            {
                Console.WriteLine(update.Title);
            }
            Console.WriteLine("Downloading...");
            UpdateDownloader downloader = uSession.CreateUpdateDownloader();
            downloader.Updates = uResult.Updates;
            downloader.Download();

            UpdateCollection updatesToInstall = new UpdateCollection();
            foreach (IUpdate update in uResult.Updates)
            {
                if (update.IsDownloaded)
                    updatesToInstall.Add(update);
            }
            Console.WriteLine("Installing...");
            IUpdateInstaller installer = uSession.CreateUpdateInstaller();
            installer.Updates = updatesToInstall;
            IInstallationResult installationRes = installer.Install();

            for (int i = 0; i < updatesToInstall.Count; i++)
            {
                if (installationRes.GetUpdateResult(i).HResult == 0)
                {
                    Console.WriteLine("Installed : " + updatesToInstall[i].Title);
                }
                else
                {
                    Console.WriteLine("Failed : " + updatesToInstall[i].Title);
                }
            }
            if (updatesToInstall.Count > 0)
            { 
                // 有任何更新就 Restart
                System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\shutdown.exe", "-f -r -t 0");
            }
        }
    }
}




********************************************************************************

2022-06-07補

防毒疑似每天更新,因此每天 reboot 好像沒必要;可能每月因 "累積更新" 安裝後 reboot 即可。

  • 2022-05 適用於 x64 系統之 Windows Server 2019 的 .NET Framework 3.5、4.7.2 和 4.8 的累積更新預覽 (KB5014090)
  • 2022-05 適用於 x64 系統 Windows Server 2019 (1809) 的累積更新 (KB5014022)
  • SQL Server 2019 RTM GDR 的安全性更新 (KB4583458)
  • Windows Defender Antivirus 反惡意程式碼平台更新 - KB4052623 (版本 4.18.2001.10)

********************************************************************************

【手動執行】

某台,沒加入 AD,順利正常完成。



****************************************

某台,加入 AD,套用部分 GCB,不靠排程執行,downloader.Download(); 執行出錯



未處理的例外狀況: System.Runtime.InteropServices.COMException: 發生例外狀況於 HRESULT: 0x80240044
於 WUApiLib.UpdateDownloaderClass.Download()
於 WindowsUpdateAndRebootConsoleApp.Program.Main(String[] args) 於 C:\CODE\WindowsUpdateAndRebootSolution\WindowsUpdateAndRebootConsoleApp\Program.cs: 行 27

0x80240044 是 WU_E_PER_MACHINE_UPDATE_ACCESS_DENIED

WUA Success and Error Codes (Wuerror.h) - Win32 apps | Microsoft Docs

WU_E_PER_MACHINE_UPDATE_ACCESS_DENIED
0x80240044
Only administrators can perform this operation on per-computer updates.

********************************************************************************

【排程執行】

Windows Server 2019 上用 local administrator 實際測試 (沒加入AD),可行。

****************************************

某台失敗,錯誤 0x80131700,Google 查到
https://support.microsoft.com/zh-tw/topic/%E4%BF%AE%E6%AD%A3-%E5%95%9F%E5%8B%95%E6%88%96%E8%A8%AD%E5%AE%9A%E4%BC%81%E6%A5%AD%E5%96%AE%E4%B8%80%E7%99%BB%E5%85%A5%E6%9C%8D%E5%8B%99%E6%99%82-%E7%99%BC%E7%94%9F0x80131700-%E9%8C%AF%E8%AA%A4%E4%BB%A3%E7%A2%BC-deb36afe-ad48-c255-05db-91bd6a7c88c0

Windows 無法在本機電腦上啟動企業單一登入服務服務。

原因

安裝 .NET Framework 4.0 之後,就會發生此問題。 ENTSSO 用來存取 SQL Server (SSOSQL)所使用之元件的註冊,不會指定正確的 .NET Framework 版本。  安裝 .NET Framework 4.0 時,元件會嘗試使用較新的架構,然後無法載入。 

解決

想到上面程式敝人一開始方案設定為 .NET Framework 4.8,這台 Windows Server 2019 預設內建安裝到 .NET Framework 4.7.2 而已,因為這樣執行失敗嗎?把專案的「屬性」中「應用程式」的「目標Framework」設定為 .NET Framework 4.x 中最小版本 ( 目前只有 .NET Framework 4.5.2 可選)。再次編譯或重建,重新用排程測試執行,順利執行成功。( 非 AD 環境的 administrator,使用 WSUS,SSMS 啟動中 )

排程執行過程有一陣子是:工作證在執行中。(0x41301),自動安裝重新啟動後,顯示:操作順利完成。(0x0)

注意,最好選一個不會要求週期性變更密碼的帳號 (例如 90天要變更一次的帳號不方便),權限夠的帳號。( 不確定是否要 administrators 群組)

****************************************

另一台加入 AD,用 (AD網域)/Renamed_Admin 啟動排程,「工作管理員」可以看到程式有啟動,但一直處於執行中。把排程停掉,「工作管理員」中刪除該程式,手動執行,發現無法執行成功 (詳見上面)。

********************************************************************************

如果編譯出現下面錯誤

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\SysWOW64\wuapi.dll" 中的 COM 參考 "WUApiLib"。在 'UpdateInstaller.get_ParentHwnd' 中至少有一個引數無法由執行階段封送處理器進行封送處理。這個引數將被當成指標傳遞,並且可能需要以不安全的程式碼操作。

請確認 wuapi.dll 是否為 C:\Windows\System32\wuapi.dll,是否選到別的目錄的。沒錯就不理會。

********************************************************************************

如果編譯出現下面錯誤

錯誤 CS1752 無法內嵌 Interop 類型 'UpdateSessionClass'。請改用適當的介面。 ConsoleApp1 C:\Code\ConsoleApp1\ConsoleApp1\Program.cs 18 作用中

請在 Visual Studio 2022 「方案總管」點選「(專案)/參考/WUApiLib」,把「內崁Interop類型」從 true 改為 false。




********************************************************************************


********************************************************************************
附錄:不同版本目標 Framework 編譯測試結果

********************************************************************************

【專案設定為 .NET Framework 2.0,編譯出現下面問題】

已開始重建...

1>------ 已開始全部重建: 專案: WindowsUpdateAndRebootConsoleApp, 組態: Debug Any CPU ------

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Core" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Core",或將應用程式的目標重定為包含 "System.Core" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3268: 無法解析主要參考 "System.Xml.Linq",因為它在架構組件 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有間接相依性,但此組件無法在目前設為目標的架構中解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Xml.Linq",或將應用程式的目標重定為包含 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3268: 無法解析主要參考 "System.Data.DataSetExtensions",因為它在架構組件 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有間接相依性,但此組件無法在目前設為目標的架構中解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Data.DataSetExtensions",或將應用程式的目標重定為包含 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Xml.Linq" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Xml.Linq",或將應用程式的目標重定為包含 "System.Xml.Linq" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Data.DataSetExtensions" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Data.DataSetExtensions",或將應用程式的目標重定為包含 "System.Data.DataSetExtensions" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "Microsoft.CSharp" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "Microsoft.CSharp",或將應用程式的目標重定為包含 "Microsoft.CSharp" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Net.Http" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v2.0"。若要解決此問題,請移除參考 "System.Net.Http",或將應用程式的目標重定為包含 "System.Net.Http" 的架構版本。

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller2.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller3.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller4.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.IUpdateInstaller4_get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>  WindowsUpdateAndRebootConsoleApp -> D:\CODE\WindowsUpdateAndRebootSolution\WindowsUpdateAndRebootConsoleApp\bin\Debug\WindowsUpdateAndRebootConsoleApp.exe

========== 全部重建: 1 成功、0 失敗、 0 略過 ==========

********************************************************************************

【專案設定為 .NET Framework 3.0,編譯出現下面問題】

已開始重建...

1>------ 已開始全部重建: 專案: WindowsUpdateAndRebootConsoleApp, 組態: Debug Any CPU ------

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Core" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Core",或將應用程式的目標重定為包含 "System.Core" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3268: 無法解析主要參考 "System.Xml.Linq",因為它在架構組件 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有間接相依性,但此組件無法在目前設為目標的架構中解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Xml.Linq",或將應用程式的目標重定為包含 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3268: 無法解析主要參考 "System.Data.DataSetExtensions",因為它在架構組件 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有間接相依性,但此組件無法在目前設為目標的架構中解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Data.DataSetExtensions",或將應用程式的目標重定為包含 "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Xml.Linq" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Xml.Linq",或將應用程式的目標重定為包含 "System.Xml.Linq" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Data.DataSetExtensions" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Data.DataSetExtensions",或將應用程式的目標重定為包含 "System.Data.DataSetExtensions" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "Microsoft.CSharp" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "Microsoft.CSharp",或將應用程式的目標重定為包含 "Microsoft.CSharp" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Net.Http" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.0"。若要解決此問題,請移除參考 "System.Net.Http",或將應用程式的目標重定為包含 "System.Net.Http" 的架構版本。

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller2.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller3.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller4.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.IUpdateInstaller4_get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>  WindowsUpdateAndRebootConsoleApp -> D:\CODE\WindowsUpdateAndRebootSolution\WindowsUpdateAndRebootConsoleApp\bin\Debug\WindowsUpdateAndRebootConsoleApp.exe

========== 全部重建: 1 成功、0 失敗、 0 略過 ==========

********************************************************************************

【專案設定為 .NET Framework 3.5,編譯出現下面問題】

已開始重建...

1>------ 已開始全部重建: 專案: WindowsUpdateAndRebootConsoleApp, 組態: Debug Any CPU ------

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "Microsoft.CSharp" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.5"。若要解決此問題,請移除參考 "Microsoft.CSharp",或將應用程式的目標重定為包含 "Microsoft.CSharp" 的架構版本。

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3267: 主要參考 "System.Net.Http" 為架構組件,無法在目前設為目標的架構中加以解析。".NETFramework,Version=v3.5"。若要解決此問題,請移除參考 "System.Net.Http",或將應用程式的目標重定為包含 "System.Net.Http" 的架構版本。

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller2.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller3.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.IUpdateInstaller4.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>TlbImp : warning TI3015: At least one of the arguments for 'WUApiLib.UpdateInstallerClass.IUpdateInstaller4_get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>  WindowsUpdateAndRebootConsoleApp -> D:\CODE\WindowsUpdateAndRebootSolution\WindowsUpdateAndRebootConsoleApp\bin\Debug\WindowsUpdateAndRebootConsoleApp.exe

========== 全部重建: 1 成功、0 失敗、 0 略過 ==========

********************************************************************************

【專案設定為 .NET Framework 4.5.2,編譯出現下面問題】

已開始重建...

1>------ 已開始全部重建: 專案: WindowsUpdateAndRebootConsoleApp, 組態: Debug Any CPU ------

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'UpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'UpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'IUpdateInstaller4.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'IUpdateInstaller3.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'IUpdateInstaller2.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2926,5): warning MSB3305: 正在處理路徑 "C:\Windows\System32\wuapi.dll" 中的 COM 參考 "WUApiLib"。At least one of the arguments for 'IUpdateInstaller.get_ParentHwnd' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.

1>  WindowsUpdateAndRebootConsoleApp -> D:\CODE\WindowsUpdateAndRebootSolution\WindowsUpdateAndRebootConsoleApp\bin\Debug\WindowsUpdateAndRebootConsoleApp.exe

========== 全部重建: 1 成功、0 失敗、 0 略過 ==========


********************************************************************************


(完)

相關

[研究][C#]呼叫 Windows Update 更新和 Reboot
https://shaurong.blogspot.com/2022/05/c-windows-update-reboot.html

[研究][WinForm][C#]偵測網站是否 Service Unavailable並 Reboot
https://shaurong.blogspot.com/2022/05/winformc-service-unavailable-reboot.html

判斷安裝的 .NET Framework 版本 - .NET Framework | Microsoft Docs
https://docs.microsoft.com/zh-tw/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed


沒有留言:

張貼留言