2 * ReactOS Win32 Applications
3 * Copyright (C) 2007 ReactOS Team
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.
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.
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.
19 /* $Id: hostname.c 21664 2006-04-19 20:14:03Z gedmurphy $
21 * COPYRIGHT : See COPYING in the top level directory
22 * PROJECT : Event Logging Utility
24 * PROGRAMMER: Marc Piulachs (marc.piulachs at codexchange [dot] net)
35 TCHAR
* m_MachineName
= NULL
;
36 TCHAR
* m_Text
= "No User Event Text";
37 TCHAR
* m_Source
= "User Event";
38 WORD m_Severity
= EVENTLOG_INFORMATION_TYPE
;
45 fputs("Usage: logevent.exe [-m \\MachineName] [options] \"Event Text\"", stderr
);
46 fputs("\n\n", stderr
);
47 fputs("Options:\n", stderr
);
48 fputs(" -s Severity one of:\n", stderr
);
49 fputs(" \t(S)uccess\n", stderr
);
50 fputs(" \t(I)nformation\n", stderr
);
51 fputs(" \t(W)arning\n", stderr
);
52 fputs(" \t(E)rror\n", stderr
);
53 fputs(" \t(F)ailure\n", stderr
);
54 fputs(" -r Source\n", stderr
);
55 fputs(" -c Category number\n", stderr
);
56 fputs(" -e Event ID\n", stderr
);
57 fputs(" /? Help\n", stderr
);
65 LPCTSTR arrLogEntry
[] = { m_Text
}; //writing just one entry
67 /* Get a handle to the Application event log */
68 hAppLog
= RegisterEventSource(
69 (LPCSTR
)m_MachineName
, /* machine */
70 (LPCSTR
)m_Source
); /* source name */
72 /* Now report the event, which will add this event to the event log */
73 bSuccess
= ReportEvent(
74 hAppLog
, /* event-log handle */
75 m_Severity
, /* event type */
76 m_Category
, /* category */
77 m_EventID
, /* event ID */
78 NULL
, /* no user SID */
79 1, /* number of substitution strings */
80 0, /* no binary data */
81 arrLogEntry
, /* string array */
82 NULL
); /* address of data */
84 DeregisterEventSource(hAppLog
);
89 /* Parse command line parameters */
90 static BOOL
ParseCmdline(int argc
, TCHAR
**argv
)
103 FoundEventText
= FALSE
;
104 InvalidOption
= FALSE
;
106 for (i
= 1; i
< argc
; i
++) {
107 if (argv
[i
][0] == '-' || argv
[i
][0] == '/') {
108 switch (argv
[i
][1]) {
111 switch (argv
[i
+ 1][0])
115 m_Severity
= EVENTLOG_SUCCESS
;
120 m_Severity
= EVENTLOG_INFORMATION_TYPE
;
125 m_Severity
= EVENTLOG_WARNING_TYPE
;
130 m_Severity
= EVENTLOG_ERROR_TYPE
;
135 m_Severity
= EVENTLOG_ERROR_TYPE
;
139 printf("Bad option %s.\n", argv
[i
]);
146 m_MachineName
= argv
[i
+ 1];
151 m_Source
= argv
[i
+ 1];
156 m_Category
= atoi(argv
[i
+ 1]);
161 m_EventID
= atoi(argv
[i
+ 1]);
168 printf("Bad option %s.\n", argv
[i
]);
173 printf("Bad option format %s.\n", argv
[i
]);
177 if (FoundEventText
) {
178 printf("Bad parameter %s.\n", argv
[i
]);
182 FoundEventText
= TRUE
;
187 if ((!ShowUsage
) && (!FoundEventText
)) {
188 printf("The event text must be specified.\n");
200 int main(int argc
, char **argv
)
202 if (ParseCmdline(argc
, argv
))