Yes there is, take a look at the System.Management classes and the WMI
"win32_OperatingSystem" class 'shutdown" method.
Following example illustrates how to call Shutdown using System.Management
and WMI:
using System;
using System.Management;
using System.Runtime.InteropServices;
public class Shutdown {
public static void Main() {
string osName = null;
ManagementObjectSearcher searcher =
new ManagementObjectSearcher( "root/cimv2", "select * from
Win32_OperatingSystem where primary=true");
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject item in collection)
{
osName = item.Properties["Name"].Value.ToString();
}
using (ManagementObject os = new
ManagementObject("Win32_OperatingSystem.Name='" + osName +"'"))
{
ManagementBaseObject inParams = null;
os.Scope.Options.EnablePrivileges = true;
ManagementBaseObject outParams = os.InvokeMethod("Shutdown", inParams,
null);
if ((System.UInt32)(outParams.Properties["ReturnValue"].Value) != 0)
{
// Failed check return code
}
}
}
}
Willy.
The .Net Framework doesn't have a class that does this on its own?