나머지는 알아서 추가 ㅡ.ㅡ;;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | public partial class Form1 : Form { [DllImport( "user32.Dll" )] public static extern int SystemParametersInfo( int uAction, int uparam, string lpvParam, int fuWinIni); public Form1() { InitializeComponent(); } public enum ShutDown { LogOff = 0, Shutdown = 1, Reboot = 2, ForcedLogOff = 4, ForcedShutdown = 5, ForcedReboot = 6, PowerOff = 8, ForcedPowerOff = 12 } private void button1_Click( object sender, EventArgs e) { // 컴퓨터 재시작 // shutDown(ShutDown.ForcedReboot); // 컴퓨터 끄기 // shutDown(ShutDown.ForcedShutdown); } // 끄기모드 private void shutDown(ShutDown flag) { ManagementBaseObject outParam = null ; ManagementClass sysOS = new ManagementClass( "Win32_OperatingSystem" ); sysOS.Get(); // enables required security privilege. sysOS.Scope.Options.EnablePrivileges = true ; // get our in parameters ManagementBaseObject inParams = sysOS.GetMethodParameters( "Win32Shutdown" ); // pass the flag of 0 = System Shutdown inParams[ "Flags" ] = flag; inParams[ "Reserved" ] = "0" ; foreach (ManagementObject manObj in sysOS.GetInstances()) { outParam = manObj.InvokeMethod( "Win32Shutdown" , inParams, null ); } } } |
댓글 없음:
댓글 쓰기