using SystemRuntimeInteropServices;
[Flags]
public enum ExitWindows : uint
{
LogOff = x //注銷
ShutDown = x //關機
Reboot = x //重啟
Force = x
PowerOff = x
ForceIfHung = x
}
[Flags]
public enum ShutdownReason : uint
{
MajorApplication = x
MajorHardware = x
MajorLegacyApi = x
MajorOperatingSystem = x
MajorOther = x
MajorPower = x
MajorSoftware = x
MajorSystem = x
MinorBlueScreen = xF
MinorCordUnplugged = xb
MinorDisk = x
MinorEnvironment = xc
MinorHardwareDriver = xd
MinorHotfix = x
MinorHung = x
MinorInstallation = x
MinorMaintenance = x
MinorMMC = x
MinorNetworkConnectivity = x
MinorNetworkCard = x
MinorOther = x
MinorOtherDriver = xe
MinorPowerSupply = xa
MinorProcessor = x
MinorReconfig = x
MinorSecurity = x
MinorSecurityFix = x
MinorSecurityFixUninstall = x
MinorServicePack = x
MinorServicePackUninstall = x
MinorTermSrv = x
MinorUnstable = x
MinorUpgrade = x
MinorWMI = x
FlagUserDefined = x
FlagPlanned = x
}
[DllImport(userdll)]
static extern bool ExitWindowsEx(ExitWindows uFlags ShutdownReason dwReason);
[STAThread]
static void Main(string[] args)
{
ExitWindowsEx(ExitWindowsLogOff ShutdownReasonMajorOther & ShutdownReasonMinorOther);
//這個語句將實現計算機注銷操作
}
From:http://tw.wingwit.com/Article/program/net/201311/12585.html