Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenlogoff.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS logoff utility 00004 * FILE: base\applications\logoff\logoff.c 00005 * PURPOSE: Logoff current session, or another session, potentially on another machine 00006 * AUTHOR: 30.07.2007 - Frode Lillerud 00007 */ 00008 00009 /* Note 00010 * This application is a lightweight version of shutdown.exe. It is intended to be function-compatible 00011 * with Windows' system32\logoff.exe commandline application. 00012 */ 00013 00014 #define NDEBUG 00015 #include "precomp.h" 00016 00017 //Commandline argument switches 00018 LPTSTR szRemoteServerName = NULL; 00019 BOOL bVerbose; 00020 00021 //---------------------------------------------------------------------- 00022 // 00023 //Retrieve resource string and output the Usage to the console 00024 // 00025 //---------------------------------------------------------------------- 00026 static void PrintUsage() { 00027 LPTSTR lpUsage = NULL; 00028 00029 if (AllocAndLoadString(&lpUsage, GetModuleHandle(NULL), IDS_USAGE)) { 00030 _putts(lpUsage); 00031 } 00032 00033 } 00034 00035 //---------------------------------------------------------------------- 00036 // 00037 // Writes the last error as both text and error code to the console. 00038 // 00039 //---------------------------------------------------------------------- 00040 void DisplayLastError() 00041 { 00042 int errorCode = GetLastError(); 00043 LPTSTR lpMsgBuf; 00044 00045 // Display the error message to the user 00046 FormatMessage( 00047 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 00048 NULL, 00049 errorCode, 00050 LANG_USER_DEFAULT, 00051 (LPTSTR) &lpMsgBuf, 00052 0, 00053 NULL); 00054 00055 _ftprintf(stderr, lpMsgBuf); 00056 _ftprintf(stderr, _T("Error code: %d\n"), errorCode); 00057 00058 LocalFree(lpMsgBuf); 00059 } 00060 00061 //---------------------------------------------------------------------- 00062 // 00063 //Sets flags based on commandline arguments 00064 // 00065 //---------------------------------------------------------------------- 00066 BOOL ParseCommandLine(int argc, TCHAR *argv[]) 00067 { 00068 int i; 00069 LPTSTR lpIllegalMsg; 00070 00071 //FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine 00072 //Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master. 00073 00074 for (i = 1; i < argc; i++) { 00075 switch(argv[i][0]){ 00076 case '-': 00077 case '/': 00078 // -v (verbose) 00079 if (argv[i][1] == 'v') { 00080 bVerbose = TRUE; 00081 break; //continue parsing the arguments 00082 } 00083 // -? (usage) 00084 else if(argv[i][1] == '?') { 00085 return FALSE; //display the Usage 00086 } 00087 default: 00088 //Invalid parameter detected 00089 if (AllocAndLoadString(&lpIllegalMsg, GetModuleHandle(NULL), IDS_ILLEGAL_PARAM)) 00090 _putts(lpIllegalMsg); 00091 return FALSE; 00092 } 00093 } 00094 00095 return TRUE; 00096 } 00097 00098 //---------------------------------------------------------------------- 00099 // 00100 //Main entry for program 00101 // 00102 //---------------------------------------------------------------------- 00103 int _tmain(int argc, TCHAR *argv[]) 00104 { 00105 LPTSTR lpLogoffRemote, lpLogoffLocal; 00106 00107 // 00108 // Parse command line 00109 // 00110 if (!ParseCommandLine(argc, argv)) { 00111 PrintUsage(); 00112 return 1; 00113 } 00114 00115 // 00116 //Should we log off session on remote server? 00117 // 00118 if (szRemoteServerName) { 00119 if (bVerbose) { 00120 if (AllocAndLoadString(&lpLogoffRemote, GetModuleHandle(NULL), IDS_LOGOFF_REMOTE)) 00121 _putts(lpLogoffRemote); 00122 } 00123 00124 //FIXME: Add Remote Procedure Call to logoff user on a remote machine 00125 _ftprintf(stderr, "Remote Procedure Call in logoff.exe has not been implemented"); 00126 } 00127 // 00128 //Perform logoff of current session on local machine instead 00129 // 00130 else { 00131 if (bVerbose) { 00132 //Get resource string, and print it. 00133 if (AllocAndLoadString(&lpLogoffLocal, GetModuleHandle(NULL), IDS_LOGOFF_LOCAL)) 00134 _putts(lpLogoffLocal); 00135 } 00136 00137 //Actual logoff 00138 if (!ExitWindows(NULL, NULL)) { 00139 DisplayLastError(); 00140 return 1; 00141 } 00142 } 00143 00144 return 0; 00145 } 00146 /* EOF */ Generated on Sat May 26 2012 04:15:46 for ReactOS by
1.7.6.1
|