c#

位置:IT落伍者 >> c# >> 浏览文章

C# 实现注销、关机、重启电脑功能


发布日期:2024年06月13日
 
C# 实现注销、关机、重启电脑功能

using SystemRuntimeInteropServices;[Flags]public enum ExitWindows : uint{LogOff = x      //注销            ShutDown = x    //关机            Reboot = x      //重启            Force = xPowerOff = xForceIfHung = x}[Flags]public enum ShutdownReason : uint{MajorApplication = xMajorHardware = xMajorLegacyApi = xMajorOperatingSystem = xMajorOther = xMajorPower = xMajorSoftware = xMajorSystem = xMinorBlueScreen = xFMinorCordUnplugged = xbMinorDisk = xMinorEnvironment = xcMinorHardwareDriver = xdMinorHotfix = xMinorHung = xMinorInstallation = xMinorMaintenance = xMinorMMC = xMinorNetworkConnectivity = xMinorNetworkCard = xMinorOther = xMinorOtherDriver = xeMinorPowerSupply = xaMinorProcessor = xMinorReconfig = xMinorSecurity = xMinorSecurityFix = xMinorSecurityFixUninstall = xMinorServicePack = xMinorServicePackUninstall = xMinorTermSrv = xMinorUnstable = xMinorUpgrade = xMinorWMI = xFlagUserDefined = xFlagPlanned = x}[DllImport(userdll)]static extern bool ExitWindowsEx(ExitWindows uFlags ShutdownReason dwReason);[STAThread]static void Main(string[] args){ExitWindowsEx(ExitWindowsLogOff ShutdownReasonMajorOther & ShutdownReasonMinorOther);//这个语句将实现计算机注销操作           }

               

上一篇:.NET的自动序列号工具

下一篇:用C#.net轻松制作不规则窗体