ReactOS 0.4.16-dev-297-gc569aee
logoff.c
Go to the documentation of this file.
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 */
27
28//----------------------------------------------------------------------
29//
30// Writes the last error as both text and error code to the console.
31//
32//----------------------------------------------------------------------
34{
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//----------------------------------------------------------------------
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 */
76 return FALSE;
77 }
78 }
79
80 return TRUE;
81}
82
83//----------------------------------------------------------------------
84//
85// Main entry for program
86//
87//----------------------------------------------------------------------
88int wmain(int argc, WCHAR *argv[])
89{
90 /* Initialize the Console Standard Streams */
92
93 /* Parse command line */
95 {
97 return 1;
98 }
99
100 /* Should we log off session on remote server? */
102 {
103 if (bVerbose)
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 */
116 }
117
118 /* Actual logoff */
119 if (!ExitWindowsEx(EWX_LOGOFF, 0))
120 {
122 return 1;
123 }
124 }
125
126 return 0;
127}
128
129/* EOF */
static int argc
Definition: ServiceArgs.c:12
#define IDS_USAGE
Definition: resource.h:3
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define IDS_ILLEGAL_PARAM
Definition: resource.h:6
#define IDS_LOGOFF_REMOTE
Definition: resource.h:4
#define IDS_LOGOFF_LOCAL
Definition: resource.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOL bVerbose
Definition: logoff.c:26
BOOL ParseCommandLine(int argc, WCHAR *argv[])
Definition: logoff.c:45
LPWSTR szRemoteServerName
Definition: logoff.c:25
VOID DisplayError(DWORD dwError)
Definition: logoff.c:33
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
int wmain()
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define EWX_LOGOFF
Definition: winuser.h:636
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184