WindowControler - Shutdown,Restart, ….
CodeKeep C# Feed Gennaio 19th, 2008
Description: Ði?u khi?n h? th?ngLink: http://www.codekeep.net/snippets/207000bf-4e15-4700-a72c-8a4f276b9293.aspx
private void DoEvent()
{
Process[] arrProc = Process.GetProcesses();
foreach ( Process childProc in arrProc)
{
System.IntPtr hWnd = childProc.MainWindowHandle;
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, SW_RESTORE);
SetForegroundWindow(hWnd);
if (!(childProc.MainWindowTitle.Equals(this.Text)))
{
childProc.CloseMainWindow();
childProc.Kill();
childProc.WaitForExit();
}
}
}
switch (cbEvent.SelectedText)
{
case "Shutdown":
WindowsController.ExitWindows(RestartOptions.ShutDown, false);
break;
case "Restart":
WindowsController.ExitWindows(RestartOptions.Reboot, false);
break;
case "Stand By":
WindowsController.ExitWindows(RestartOptions.Suspend, false);
break;
case "Hibernate":
WindowsController.ExitWindows(RestartOptions.Hibernate, false);
break;
case "Log Off":
WindowsController.ExitWindows(RestartOptions.LogOff, false);
break;
}
}