tôi tìm thấy mã này trên một chủ đề cũ để shutdown máy tính cục bộ:WMI để khởi động lại máy từ xa
using System.Management;
void Shutdown()
{
ManagementBaseObject mboShutdown = null;
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
mcWin32.Get();
// You can't shutdown without security privileges
mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams =
mcWin32.GetMethodParameters("Win32Shutdown");
// Flag 1 means we want to shut down the system. Use "2" to reboot.
mboShutdownParams["Flags"] = "1";
mboShutdownParams["Reserved"] = "0";
foreach (ManagementObject manObj in mcWin32.GetInstances())
{
mboShutdown = manObj.InvokeMethod("Win32Shutdown",
mboShutdownParams, null);
}
}
Có thể sử dụng một phương pháp WMI tương tự như khởi động lại cờ "2" một máy từ xa, mà tôi chỉ có tên máy chứ không phải IPaddress.
EDIT: Tôi hiện có:
SearchResultCollection allMachinesCollected = machineSearch.FindAll();
Methods myMethods = new Methods();
string pcName;
ArrayList allComputers = new ArrayList();
foreach (SearchResult oneMachine in allMachinesCollected)
{
//pcName = oneMachine.Properties.PropertyNames.ToString();
pcName = oneMachine.Properties["name"][0].ToString();
allComputers.Add(pcName);
MessageBox.Show(pcName + "has been sent the restart command.");
Process.Start("shutdown.exe", "-r -f -t 0 -m \\" + pcName);
}
nhưng điều này không làm việc, và tôi muốn WMI đi về phía trước.
Để tham khảo, các "Flags" giá trị của 2 là những gì biến yêu cầu tắt máy này thành khởi động lại. Danh sách đầy đủ các lá cờ ở đây: https://msdn.microsoft.com/en-us/library/aa394058(v=vs.85).aspx – Ceilingfish