熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C# 實現注銷、關機、重啟電腦功能

2013-11-13 10:06:35  來源: .NET編程 


  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
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.