[RAPPS] Bulk install!
[reactos.git] / reactos / base / applications / logoff / logoff.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS logoff utility
4 * FILE: base/applications/logoff/logoff.c
5 * PURPOSE: Logoff current session, or another session, potentially on another machine
6 * AUTHOR: 30.07.2007 - Frode Lillerud
7 */
8
9 /* Note
10 * This application is a lightweight version of shutdown.exe. It is intended
11 * to be function-compatible with Windows' system32\logoff.exe application.
12 */
13
14 #include <stdio.h>
15
16 #include <windef.h>
17 #include <winbase.h>
18 #include <winuser.h>
19
20 #include <conutils.h>
21
22 #include "resource.h"
23
24 /* Command-line argument switches */
25 LPWSTR szRemoteServerName = NULL;
26 BOOL bVerbose;
27
28 //----------------------------------------------------------------------
29 //
30 // Writes the last error as both text and error code to the console.
31 //
32 //----------------------------------------------------------------------
33 VOID DisplayError(DWORD dwError)
34 {
35 ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM,
36 NULL, dwError, LANG_USER_DEFAULT);
37 ConPrintf(StdErr, L"Error code: %lu\n", dwError);
38 }
39
40 //----------------------------------------------------------------------
41 //
42 // Sets flags based on command-line arguments
43 //
44 //----------------------------------------------------------------------
45 BOOL ParseCommandLine(int argc, WCHAR *argv[])
46 {
47 int i;
48
49 // FIXME: Add handling of command-line arguments to select
50 // the session number and name, and also name of remote machine.
51 // Example: logoff.exe 4 /SERVER:Master
52 // should logoff session number 4 on remote machine called Master.
53
54 for (i = 1; i < argc; i++)
55 {
56 switch (argv[i][0])
57 {
58 case L'-':
59 case L'/':
60 // -v (verbose)
61 if (argv[i][1] == L'v')
62 {
63 bVerbose = TRUE;
64 break;
65 }
66 // -? (usage)
67 else if (argv[i][1] == L'?')
68 {
69 /* Will display the Usage */
70 return FALSE;
71 }
72 /* Fall through */
73 default:
74 /* Invalid parameter detected */
75 ConResPuts(StdErr, IDS_ILLEGAL_PARAM);
76 return FALSE;
77 }
78 }
79
80 return TRUE;
81 }
82
83 //----------------------------------------------------------------------
84 //
85 // Main entry for program
86 //
87 //----------------------------------------------------------------------
88 int wmain(int argc, WCHAR *argv[])
89 {
90 /* Initialize the Console Standard Streams */
91 ConInitStdStreams();
92
93 /* Parse command line */
94 if (!ParseCommandLine(argc, argv))
95 {
96 ConResPuts(StdOut, IDS_USAGE);
97 return 1;
98 }
99
100 /* Should we log off session on remote server? */
101 if (szRemoteServerName)
102 {
103 if (bVerbose)
104 ConResPuts(StdOut, IDS_LOGOFF_REMOTE);
105
106 // FIXME: Add Remote Procedure Call to logoff user on a remote machine
107 ConPuts(StdErr, L"Remote Procedure Call in logoff.exe has not been implemented");
108 }
109 /* Perform logoff of current session on local machine instead */
110 else
111 {
112 if (bVerbose)
113 {
114 /* Get resource string and print it */
115 ConResPuts(StdOut, IDS_LOGOFF_LOCAL);
116 }
117
118 /* Actual logoff */
119 if (!ExitWindowsEx(EWX_LOGOFF, 0))
120 {
121 DisplayError(GetLastError());
122 return 1;
123 }
124 }
125
126 return 0;
127 }
128
129 /* EOF */