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
)) {
37 //----------------------------------------------------------------------
39 // Writes the last error as both text and error code to the console.
41 //----------------------------------------------------------------------
42 void DisplayLastError()
44 int errorCode
= GetLastError();
47 // Display the error message to the user
49 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
57 _ftprintf(stderr
, lpMsgBuf
);
58 _ftprintf(stderr
, _T("Error code: %d\n"), errorCode
);
63 //----------------------------------------------------------------------
65 //Sets flags based on commandline arguments
67 //----------------------------------------------------------------------
68 BOOL
ParseCommandLine(int argc
, TCHAR
*argv
[])
73 //FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine
74 //Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master.
76 for (i
= 1; i
< argc
; i
++) {
81 if (argv
[i
][1] == 'v') {
83 break; //continue parsing the arguments
86 else if(argv
[i
][1] == '?') {
87 return FALSE
; //display the Usage
90 //Invalid parameter detected
91 if (AllocAndLoadString(&lpIllegalMsg
, GetModuleHandle(NULL
), IDS_ILLEGAL_PARAM
))
100 //----------------------------------------------------------------------
102 //Main entry for program
104 //----------------------------------------------------------------------
105 int _tmain(int argc
, TCHAR
*argv
[])
107 LPTSTR lpLogoffRemote
, lpLogoffLocal
;
110 // Parse command line
112 if (!ParseCommandLine(argc
, argv
)) {
118 //Should we log off session on remote server?
120 if (szRemoteServerName
) {
122 if (AllocAndLoadString(&lpLogoffRemote
, GetModuleHandle(NULL
), IDS_LOGOFF_REMOTE
))
123 _putts(lpLogoffRemote
);
126 //FIXME: Add Remote Procedure Call to logoff user on a remote machine
127 _ftprintf(stderr
, "Remote Procedure Call in logoff.exe has not been implemented");
130 //Perform logoff of current session on local machine instead
134 //Get resource string, and print it.
135 if (AllocAndLoadString(&lpLogoffLocal
, GetModuleHandle(NULL
), IDS_LOGOFF_LOCAL
))
136 _putts(lpLogoffLocal
);
140 if (!ExitWindows(NULL
, NULL
)) {