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

Annotation of /trunk/NexusPowerCommand/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

1 william 26 //#define USE_TESTING_CODE // when defined, no actuall power command will be processed, it will just ouput a message to the console
2 william 23 using System;
3 william 22 using System.Collections.Generic;
4     using System.Linq;
5     using System.Text;
6 william 23 using System.Reflection;
7 william 22
8     namespace NexusPowerCommand
9     {
10 william 23
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 william 22 class Program
21     {
22     static void Main(string[] args)
23     {
24 william 23 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 william 22 }
36 william 23
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 william 29 win32api.Shutdown();
58 william 23 }
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 william 29 win32api.Restart();
66 william 23 }
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 william 29 win32api.LogOff();
74 william 23 }
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 william 27 win32api.LockScreen();
82 william 23 }
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 william 29 win32api.Sleep();
90 william 23 }
91 william 22 }
92     }

  ViewVC Help
Powered by ViewVC 1.1.22