目標機器的防火牆已關閉。遠程訪問權限全開了。
代碼如下:
ConnectionOptions co = new ConnectionOptions();
co.Username = "administrator";
co.Password = "";
System.Management.ManagementScope ms = new ManagementScope("\\\\192.168.1.30\\root\\cimv2", co);
ms.Connect();
System.Management.ObjectQuery oq = new ObjectQuery("SELECT*FROM Win32_OperatingSystem");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
{
string[] ss = { "" };
mo.InvokeMethod("Reboot", ss);
Console.WriteLine(mo.ToString());
報錯地方是ms.connect();提示說要有足夠的資源權限。如何解決。
管理員設置一個密碼試試。