/[NexusPowerControl]/trunk/NexusPowerCommand/win32api.cs
ViewVC logotype

Contents of /trunk/NexusPowerCommand/win32api.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Oct 25 08:39:03 2011 UTC (8 years, 1 month ago) by william
File size: 3710 byte(s)
minor changes to code

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Runtime.InteropServices;
6 using System.Windows.Forms;
7
8 namespace NexusPowerCommand
9 {
10 public class win32api
11 {
12 #region win32api defined
13 [DllImport("user32.dll")]
14 private static extern bool LockWorkStation();
15 [DllImport("user32.dll")]
16 static extern bool ExitWindowsEx(win32api.enums.ExitWindows uFlags, win32api.enums.ShutdownReason dwReason);
17 #endregion
18
19 #region win32api enums
20 private class enums
21 {
22 [Flags]
23 internal enum ExitWindows : uint
24 {
25 // ONE of the following five:
26 LogOff = 0x00,
27 ShutDown = 0x01,
28 Reboot = 0x02,
29 PowerOff = 0x08,
30 RestartApps = 0x40,
31 // plus AT MOST ONE of the following two:
32 Force = 0x04,
33 ForceIfHung = 0x10,
34 }
35
36 [Flags]
37 internal enum ShutdownReason : uint
38 {
39 MajorApplication = 0x00040000,
40 MajorHardware = 0x00010000,
41 MajorLegacyApi = 0x00070000,
42 MajorOperatingSystem = 0x00020000,
43 MajorOther = 0x00000000,
44 MajorPower = 0x00060000,
45 MajorSoftware = 0x00030000,
46 MajorSystem = 0x00050000,
47
48 MinorBlueScreen = 0x0000000F,
49 MinorCordUnplugged = 0x0000000b,
50 MinorDisk = 0x00000007,
51 MinorEnvironment = 0x0000000c,
52 MinorHardwareDriver = 0x0000000d,
53 MinorHotfix = 0x00000011,
54 MinorHung = 0x00000005,
55 MinorInstallation = 0x00000002,
56 MinorMaintenance = 0x00000001,
57 MinorMMC = 0x00000019,
58 MinorNetworkConnectivity = 0x00000014,
59 MinorNetworkCard = 0x00000009,
60 MinorOther = 0x00000000,
61 MinorOtherDriver = 0x0000000e,
62 MinorPowerSupply = 0x0000000a,
63 MinorProcessor = 0x00000008,
64 MinorReconfig = 0x00000004,
65 MinorSecurity = 0x00000013,
66 MinorSecurityFix = 0x00000012,
67 MinorSecurityFixUninstall = 0x00000018,
68 MinorServicePack = 0x00000010,
69 MinorServicePackUninstall = 0x00000016,
70 MinorTermSrv = 0x00000020,
71 MinorUnstable = 0x00000006,
72 MinorUpgrade = 0x00000003,
73 MinorWMI = 0x00000015,
74
75 FlagUserDefined = 0x40000000,
76 FlagPlanned = 0x80000000
77 }
78 }
79 #endregion
80
81
82 #region win32api wrappers
83
84
85 public static bool Shutdown() { return win32api.ExitWindowsEx(win32api.enums.ExitWindows.ShutDown, win32api.enums.ShutdownReason.MajorOther & win32api.enums.ShutdownReason.MinorOther); }
86 public static bool Restart() { return win32api.ExitWindowsEx(win32api.enums.ExitWindows.Reboot, win32api.enums.ShutdownReason.MajorOther & win32api.enums.ShutdownReason.MinorOther); }
87
88 public static bool LogOff() { return win32api.ExitWindowsEx((uint)win32api.enums.ExitWindows.LogOff, win32api.enums.ShutdownReason.MajorOther & win32api.enums.ShutdownReason.MinorOther); }
89 public static bool LockScreen() { return win32api.LockWorkStation(); }
90 public static bool Sleep() { return Application.SetSuspendState(PowerState.Hibernate, false, false); }
91 #endregion
92 }
93 }

  ViewVC Help
Powered by ViewVC 1.1.22