ReactOS 0.4.15-dev-7942-gd23573b
logevent.c File Reference
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <tchar.h>
#include <stdarg.h>
Include dependency graph for logevent.c:

Go to the source code of this file.

Functions

void Usage (VOID)
 
void WriteEvent (VOID)
 
static BOOL ParseCmdline (int argc, TCHAR **argv)
 
int main (int argc, char **argv)
 

Variables

TCHARm_MachineName = NULL
 
TCHARm_Text = "No User Event Text"
 
TCHARm_Source = "User Event"
 
WORD m_Severity = EVENTLOG_INFORMATION_TYPE
 
WORD m_Category = 0
 
DWORD m_EventID = 1
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 199 of file logevent.c.

200{
201 if (ParseCmdline(argc, argv))
202 WriteEvent ();
203
204 return 0;
205}
static int argc
Definition: ServiceArgs.c:12
void WriteEvent(VOID)
Definition: logevent.c:60
static BOOL ParseCmdline(int argc, TCHAR **argv)
Definition: logevent.c:89
#define argv
Definition: mplay32.c:18

◆ ParseCmdline()

static BOOL ParseCmdline ( int  argc,
TCHAR **  argv 
)
static

Definition at line 89 of file logevent.c.

90{
91 INT i;
93 BOOL FoundEventText;
95
96 if (argc < 2) {
98 } else {
100 }
101
102 FoundEventText = FALSE;
104
105 for (i = 1; i < argc; i++) {
106 if (argv[i][0] == '-' || argv[i][0] == '/') {
107 switch (argv[i][1]) {
108 case 's':
109 case 'S':
110 switch (argv[i + 1][0])
111 {
112 case 's':
113 case 'S':
115 i++;
116 break;
117 case 'i':
118 case 'I':
120 i++;
121 break;
122 case 'w':
123 case 'W':
125 i++;
126 break;
127 case 'e':
128 case 'E':
130 i++;
131 break;
132 case 'f':
133 case 'F':
135 i++;
136 break;
137 default:
138 printf("Bad option %s.\n", argv[i]);
139 Usage();
140 return FALSE;
141 }
142 break;
143 case 'm':
144 case 'M':
145 m_MachineName = argv[i + 1];
146 i++;
147 break;
148 case 'r':
149 case 'R':
150 m_Source = argv[i + 1];
151 i++;
152 break;
153 case 'c':
154 case 'C':
155 m_Category = atoi(argv[i + 1]);
156 i++;
157 break;
158 case 'e':
159 case 'E':
160 m_EventID = atoi(argv[i + 1]);
161 i++;
162 break;
163 case '?':
164 ShowUsage = TRUE;
165 break;
166 default:
167 printf("Bad option %s.\n", argv[i]);
168 Usage();
169 return FALSE;
170 }
171 if (InvalidOption) {
172 printf("Bad option format %s.\n", argv[i]);
173 return FALSE;
174 }
175 } else {
176 if (FoundEventText) {
177 printf("Bad parameter %s.\n", argv[i]);
178 return FALSE;
179 } else {
180 m_Text = argv[i];
181 FoundEventText = TRUE;
182 }
183 }
184 }
185
186 if ((!ShowUsage) && (!FoundEventText)) {
187 printf("The event text must be specified.\n");
188 return FALSE;
189 }
190
191 if (ShowUsage) {
192 Usage();
193 return FALSE;
194 }
195
196 return TRUE;
197}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ InvalidOption
Definition: eventcreate.c:714
unsigned int BOOL
Definition: ntddk_ex.h:94
#define printf
Definition: freeldr.h:97
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
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
WORD m_Category
Definition: logevent.c:38
TCHAR * m_Text
Definition: logevent.c:35
WORD m_Severity
Definition: logevent.c:37
DWORD m_EventID
Definition: logevent.c:39
TCHAR * m_Source
Definition: logevent.c:36
TCHAR * m_MachineName
Definition: logevent.c:34
static void ShowUsage(int ExitCode)
Definition: msiexec.c:50
int32_t INT
Definition: typedefs.h:58
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2834
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2836
#define EVENTLOG_SUCCESS
Definition: winnt_old.h:2833
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2835

Referenced by main().

◆ Usage()

void Usage ( VOID  )

Definition at line 42 of file logevent.c.

43{
44 fputs("Usage: logevent.exe [-m \\MachineName] [options] \"Event Text\"", stderr);
45 fputs("\n\n", stderr);
46 fputs("Options:\n", stderr);
47 fputs(" -s Severity one of:\n", stderr);
48 fputs(" \t(S)uccess\n", stderr);
49 fputs(" \t(I)nformation\n", stderr);
50 fputs(" \t(W)arning\n", stderr);
51 fputs(" \t(E)rror\n", stderr);
52 fputs(" \t(F)ailure\n", stderr);
53 fputs(" -r Source\n", stderr);
54 fputs(" -c Category number\n", stderr);
55 fputs(" -e Event ID\n", stderr);
56 fputs(" /? Help\n", stderr);
57}
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)

◆ WriteEvent()

void WriteEvent ( VOID  )

Definition at line 60 of file logevent.c.

61{
62 HANDLE hAppLog;
64 LPCTSTR arrLogEntry[] = { m_Text }; //writing just one entry
65
66 /* Get a handle to the Application event log */
67 hAppLog = RegisterEventSource(
68 (LPCSTR)m_MachineName, /* machine */
69 (LPCSTR)m_Source); /* source name */
70
71 /* Now report the event, which will add this event to the event log */
73 hAppLog, /* event-log handle */
74 m_Severity, /* event type */
75 m_Category, /* category */
76 m_EventID, /* event ID */
77 NULL, /* no user SID */
78 1, /* number of substitution strings */
79 0, /* no binary data */
80 arrLogEntry, /* string array */
81 NULL); /* address of data */
82
83 DeregisterEventSource(hAppLog);
84
85 return;
86}
#define NULL
Definition: types.h:112
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define ReportEvent
Definition: winbase.h:3899
#define RegisterEventSource
Definition: winbase.h:3894
const char * LPCSTR
Definition: xmlstorage.h:183
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

Referenced by main().

Variable Documentation

◆ m_Category

WORD m_Category = 0

Definition at line 38 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_EventID

DWORD m_EventID = 1

Definition at line 39 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_MachineName

TCHAR* m_MachineName = NULL

Definition at line 34 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Severity

Definition at line 37 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Source

TCHAR* m_Source = "User Event"

Definition at line 36 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Text

TCHAR* m_Text = "No User Event Text"