ReactOS 0.4.15-dev-8222-g9164419
logevent.c
Go to the documentation of this file.
1/*
2 * ReactOS Win32 Applications
3 * Copyright (C) 2007 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19/*
20 * COPYRIGHT : See COPYING in the top level directory
21 * PROJECT : Event Logging Utility
22 * FILE : logevent.c
23 * PROGRAMMER: Marc Piulachs (marc.piulachs at codexchange [dot] net)
24 */
25
26#include <windows.h>
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30#include <malloc.h>
31#include <tchar.h>
32#include <stdarg.h>
33
35TCHAR* m_Text = "No User Event Text";
36TCHAR* m_Source = "User Event";
40
41void
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}
58
59void
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}
87
88/* Parse command line parameters */
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}
198
199int main(int argc, char **argv)
200{
201 if (ParseCmdline(argc, argv))
202 WriteEvent ();
203
204 return 0;
205}
static int argc
Definition: ServiceArgs.c:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
static BOOLEAN bSuccess
Definition: drive.cpp:433
int main()
Definition: test.c:6
@ InvalidOption
Definition: eventcreate.c:714
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#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
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
WORD m_Category
Definition: logevent.c:38
TCHAR * m_Text
Definition: logevent.c:35
void WriteEvent(VOID)
Definition: logevent.c:60
WORD m_Severity
Definition: logevent.c:37
static BOOL ParseCmdline(int argc, TCHAR **argv)
Definition: logevent.c:89
DWORD m_EventID
Definition: logevent.c:39
TCHAR * m_Source
Definition: logevent.c:36
TCHAR * m_MachineName
Definition: logevent.c:34
#define argv
Definition: mplay32.c:18
static void ShowUsage(int ExitCode)
Definition: msiexec.c:50
int32_t INT
Definition: typedefs.h:58
#define ReportEvent
Definition: winbase.h:3899
#define RegisterEventSource
Definition: winbase.h:3894
#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
char TCHAR
Definition: xmlstorage.h:189
const char * LPCSTR
Definition: xmlstorage.h:183
const CHAR * LPCTSTR
Definition: xmlstorage.h:193