ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/NexusPowerControl/trunk/NexusPowerCommand/Program.cs
Revision: 29
Committed: Tue Oct 25 08:11:08 2011 UTC (11 years, 11 months ago) by william
File size: 3268 byte(s)
Log Message:
add code stubs for:
+ Shutdown
+ Restart
+ Logoff
+ Sleep

File Contents

# Content
1 //#define USE_TESTING_CODE // when defined, no actuall power command will be processed, it will just ouput a message to the console
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Reflection;
7
8 namespace NexusPowerCommand
9 {
10
11 public class PowerCommands
12 {
13 public const string shutdown = "/shutdown";
14 public const string restart = "/restart";
15 public const string logoff = "/logoff";
16 public const string lockscreen = "/lock";
17 public const string sleep = "/sleep";
18 }
19
20 class Program
21 {
22 static void Main(string[] args)
23 {
24 if (args.Length == 0 || args.Length > 1) { ShowUsage(); return; }
25
26 switch (args[0].ToLower())
27 {
28 case PowerCommands.shutdown: Shutdown(); return;
29 case PowerCommands.restart: Restart(); return;
30 case PowerCommands.logoff: Logoff(); return;
31 case PowerCommands.lockscreen: Lock(); return;
32 case PowerCommands.sleep: Sleep(); return;
33 default: ShowUsage(); return;
34 }
35 }
36
37
38 private static void ShowUsage()
39 {
40 Console.WriteLine();
41 Console.WriteLine(string.Format("USAGE: {0}.exe <option>", Assembly.GetExecutingAssembly().GetName().Name));
42 Console.WriteLine();
43 Console.WriteLine("Where <option> is one of: ");
44 Console.WriteLine();
45 Console.WriteLine(string.Format("\t{0} = {1}","/shutdown","Shuts down the computer."));
46 Console.WriteLine(string.Format("\t{0} = {1}", "/restart", "Restarts the computer."));
47 Console.WriteLine(string.Format("\t{0} = {1}", "/logoff", "Logs off the current user."));
48 Console.WriteLine(string.Format("\t{0} = {1}", "/lock", "Locks the current user's session."));
49 Console.WriteLine(string.Format("\t{0} = {1}", "/sleep", "Puts the computer to sleep."));
50 }
51 private static void Shutdown()
52 {
53 #if USE_TESTING_CODE
54 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.shutdown));
55 return;
56 #endif
57 win32api.Shutdown();
58 }
59 private static void Restart()
60 {
61 #if USE_TESTING_CODE
62 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.restart));
63 return;
64 #endif
65 win32api.Restart();
66 }
67 private static void Logoff()
68 {
69 #if USE_TESTING_CODE
70 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.logoff));
71 return;
72 #endif
73 win32api.LogOff();
74 }
75 private static void Lock()
76 {
77 #if USE_TESTING_CODE
78 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.lockscreen));
79 return;
80 #endif
81 win32api.LockScreen();
82 }
83 private static void Sleep()
84 {
85 #if USE_TESTING_CODE
86 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.sleep));
87 return;
88 #endif
89 win32api.Sleep();
90 }
91 }
92 }