Ho trovato questo codice su una vecchia filo per arrestare la macchina locale:WMI per riavviare computer remoto
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);
}
}
E 'possibile utilizzare un metodo WMI simile riavviare flag "2" un computer remoto, per cui ho solo il nome della macchina, non l'indirizzo IP.
EDIT: Al momento ho:
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);
}
, ma questo non funziona, e preferirei WMI andando avanti.
di rinvio, il "Flags" valore 2 è ciò che trasforma questa richiesta di spegnimento in un riavvio. Elenco completo di flag qui: https://msdn.microsoft.com/en-us/library/aa394058(v=vs.85).aspx – Ceilingfish