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
10 * This application is a lightweight version of shutdown.exe. It is intended to be function-compatible
11 * with Windows' system32\logoff.exe commandline application.
19 //Commandline argument switches
20 LPTSTR szRemoteServerName
= NULL
;
23 //----------------------------------------------------------------------
25 //Retrieve resource string and output the Usage to the console
27 //----------------------------------------------------------------------
28 static void PrintUsage() {
29 LPTSTR lpUsage
= NULL
;
31 if (AllocAndLoadString(&lpUsage
, GetModuleHandle(NULL
), IDS_USAGE
)) {
38 //----------------------------------------------------------------------
40 // Writes the last error as both text and error code to the console.
42 //----------------------------------------------------------------------
43 void DisplayLastError()
45 int errorCode
= GetLastError();
48 // Display the error message to the user
50 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
58 _ftprintf(stderr
, lpMsgBuf
);
59 _ftprintf(stderr
, _T("Error code: %d\n"), errorCode
);
64 //----------------------------------------------------------------------
66 //Sets flags based on commandline arguments
68 //----------------------------------------------------------------------
69 BOOL
ParseCommandLine(int argc
, TCHAR
*argv
[])
74 //FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine
75 //Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master.
77 for (i
= 1; i
< argc
; i
++) {
82 if (argv
[i
][1] == 'v') {
84 break; //continue parsing the arguments
87 else if(argv
[i
][1] == '?') {
88 return FALSE
; //display the Usage
91 //Invalid parameter detected
92 if (AllocAndLoadString(&lpIllegalMsg
, GetModuleHandle(NULL
), IDS_ILLEGAL_PARAM
)) {
94 LocalFree(lpIllegalMsg
);
103 //----------------------------------------------------------------------
105 //Main entry for program
107 //----------------------------------------------------------------------
108 int _tmain(int argc
, TCHAR
*argv
[])
110 LPTSTR lpLogoffRemote
, lpLogoffLocal
;
113 // Parse command line
115 if (!ParseCommandLine(argc
, argv
)) {
121 //Should we log off session on remote server?
123 if (szRemoteServerName
) {
125 if (AllocAndLoadString(&lpLogoffRemote
, GetModuleHandle(NULL
), IDS_LOGOFF_REMOTE
))
126 _putts(lpLogoffRemote
);
129 //FIXME: Add Remote Procedure Call to logoff user on a remote machine
130 _ftprintf(stderr
, "Remote Procedure Call in logoff.exe has not been implemented");
133 //Perform logoff of current session on local machine instead
137 //Get resource string, and print it.
138 if (AllocAndLoadString(&lpLogoffLocal
, GetModuleHandle(NULL
), IDS_LOGOFF_LOCAL
))
139 _putts(lpLogoffLocal
);
143 if (!ExitWindows(NULL
, NULL
)) {