After some of you discuss how to reset my computer and or turn it off from C #, I found this explanation on how to do it:
ManagementBaseObject outParameters = null;
ManagementClass sysOS = new ManagementClass("Win32_OperatingSystem");
sysOS.Get();
sysOS.Scope.Options.EnablePrivileges = true;
ManagementBaseObject inParameters = sysOS.GetMethodParameters("Win32Shutdown");
inParameters["Flags"] = "1";
inParameters["Reserved"] = "0";
foreach (ManagementObject manObj in sysOS.GetInstances())
{
outParameters = manObj.InvokeMethod("Win32Shutdown", inParameters, null);
}
This worked on Windows 7, but not on a Windows XP window, I tried it. Therefore, I realized that it allows me to switch to a simpler solution:
Process.Start("shutdown", "/s /t 00");
, , , Windows 7, Windows XP box. Windows XP, , , , , , ... - , , ( , sys X, ...) ? FormClosing:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (!canExit)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
else
{
List<String> logs = LogUtil.getLog();
TextWriter tw = new StreamWriter(userAppData + "\\logTMC.txt", true);
tw.WriteLine("----- " + DateTime.Now + " ------");
foreach (String log in logs)
{
tw.WriteLine(log);
}
tw.Close();
}
}
, reset, # Windows 7, Windows XP... , - ? ? , , ? - reset, , Windows XP, , SVN Windows, , .
, , . Process.Start() , , " " ?