Tom Elliott

Tom Elliott

  • NA
  • 6
  • 0

Shutdown Help

Jun 21 2006 9:22 AM
I am trying to force a shutdown of a computer using the following secion of code:

System.Diagnostics.Process[] processes =

System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process

processParent in processes)

{

System.Diagnostics.Process[] processNames =

System.Diagnostics.Process.

GetProcessesByName

(processParent.ProcessName);

foreach (System.Diagnostics.Process

processChild in processNames)

{

try

{

System.IntPtr hWnd =

processChild.MainWindowHandle;

if (IsIconic(hWnd))

{

ShowWindowAsync(hWnd, SW_RESTORE);

}

SetForegroundWindow(hWnd);

if (!(processChild.

MainWindowTitle.Equals(this.Text)))

{

processChild.CloseMainWindow();

processChild.Kill();

processChild.WaitForExit();

}

}

catch (System.Exception exception)

{

}

}

}

Full code can be found: http://www.codeproject.com/csharp/timercomputershutdown.asp 

I am only using this part of the code to shut down, however, i am only restarting the computer, not powering down for good.

Can anyone shed some light onto this?

Thanks