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

Contents of /trunk/NexusPowerCommand/win32api.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations) (download)
Tue Oct 25 08:11:08 2011 UTC (10 years, 6 months ago) by william
File size: 3612 byte(s)
add code stubs for:
+ Shutdown
+ Restart
+ Logoff
+ Sleep

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

  ViewVC Help
Powered by ViewVC 1.1.22