Author: cfinck
Date: Sat Sep 8 12:31:56 2007
New Revision: 28935
URL:
http://svn.reactos.org/svn/reactos?rev=28935&view=rev
Log:
Add a "logevent" utility for adding an event to the EventLog, developed by Marc
Piulachs (marc DOT piulachs AT codexchange DOT net)
See issue #2598 for more details.
Added:
trunk/rosapps/logevent/
trunk/rosapps/logevent/logevent.c
trunk/rosapps/logevent/logevent.rbuild
trunk/rosapps/logevent/logevent.rc
Modified:
trunk/rosapps/directory.rbuild
Modified: trunk/rosapps/directory.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/directory.rbuild?rev=28935…
==============================================================================
--- trunk/rosapps/directory.rbuild (original)
+++ trunk/rosapps/directory.rbuild Sat Sep 8 12:31:56 2007
@@ -49,6 +49,10 @@
</directory>
-->
+<directory name="logevent">
+ <xi:include href="logevent/logevent.rbuild" />
+</directory>
+
<directory name="magnify">
<xi:include href="magnify/magnify.rbuild" />
</directory>
Added: trunk/rosapps/logevent/logevent.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/logevent/logevent.c?rev=28…
==============================================================================
--- trunk/rosapps/logevent/logevent.c (added)
+++ trunk/rosapps/logevent/logevent.c Sat Sep 8 12:31:56 2007
@@ -1,0 +1,182 @@
+/*
+ * ReactOS Win32 Applications
+ * Copyright (C) 2007 ReactOS Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/* $Id: hostname.c 21664 2006-04-19 20:14:03Z gedmurphy $
+ *
+ * COPYRIGHT : See COPYING in the top level directory
+ * PROJECT : Event Logging Utility
+ * FILE : logevent.c
+ * PROGRAMMER: Marc Piulachs (marc.piulachs at codexchange [dot] net)
+ */
+
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <tchar.h>
+#include <stdarg.h>
+
+TCHAR* m_MachineName = NULL;
+TCHAR* m_Text = "No User Event Text";
+TCHAR* m_Source = "User Event";
+WORD m_Severity = EVENTLOG_INFORMATION_TYPE;
+WORD m_Category = 0;
+DWORD m_EventID = 1;
+
+void
+Usage(VOID)
+{
+ fputs("logevent.exe [-m \\MachineName] [options] \"Event Text\"",
stderr);
+ fputs("\n", stderr);
+ fputs(" Options:\n", stderr);
+ fputs(" -s Severity one of :\n", stderr);
+ fputs(" (S)uccess\n", stderr);
+ fputs(" (I)nformation\n", stderr);
+ fputs(" (W)arning\n", stderr);
+ fputs(" (E)rror\n", stderr);
+ fputs(" (F)ailure\n", stderr);
+ fputs(" -r Source\n", stderr);
+ fputs(" -c Category number\n", stderr);
+ fputs(" -e Event ID\n", stderr);
+ fputs(" /? Help\n", stderr);
+}
+
+void
+WriteEvent (VOID)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+ LPCTSTR arrLogEntry[] = { m_Text }; //writing just one entry
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(
+ (LPCSTR)m_MachineName, /* machine */
+ (LPCSTR)m_Source); /* source name */
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(
+ hAppLog, /* event-log handle */
+ m_Severity, /* event type */
+ m_Category, /* category */
+ m_EventID, /* event ID */
+ NULL, /* no user SID */
+ 1, /* number of substitution strings */
+ 0, /* no binary data */
+ arrLogEntry, /* string array */
+ NULL); /* address of data */
+
+ DeregisterEventSource(hAppLog);
+
+ return;
+}
+
+/* Parse command line parameters */
+static BOOL ParseCmdline(int argc, TCHAR **argv)
+{
+ INT i;
+ BOOL ShowUsage;
+ BOOL FoundEventText;
+ BOOL InvalidOption;
+
+ if (argc < 2) {
+ ShowUsage = TRUE;
+ } else {
+ ShowUsage = FALSE;
+ }
+
+ FoundEventText = FALSE;
+ InvalidOption = FALSE;
+
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] == '-' || argv[i][0] == '/') {
+ switch (argv[i][1]) {
+ case 's':
+ switch (argv[i + 1][0])
+ {
+ case 's':
+ m_Severity = EVENTLOG_SUCCESS;
+ i++;
+ break;
+ case 'i':
+ m_Severity = EVENTLOG_INFORMATION_TYPE;
+ i++;
+ break;
+ case 'w':
+ m_Severity = EVENTLOG_WARNING_TYPE;
+ i++;
+ break;
+ case 'e':
+ m_Severity = EVENTLOG_ERROR_TYPE;
+ i++;
+ break;
+ case 'f':
+ m_Severity = EVENTLOG_ERROR_TYPE;
+ i++;
+ break;
+ default:
+ printf("Bad option %s.\n", argv[i]);
+ Usage();
+ return FALSE;
+ }
+ break;
+ case 'm': m_MachineName = argv[i + 1]; i++; break;
+ case 'r': m_Source = argv[i + 1]; i++; break;
+ case 'c': m_Category = atoi(argv[i + 1]); i++; break;
+ case 'e': m_EventID = atoi(argv[i + 1]); i++; break;
+ case 'h': ShowUsage = TRUE; break;
+ default:
+ printf("Bad option %s.\n", argv[i]);
+ Usage();
+ return FALSE;
+ }
+ if (InvalidOption) {
+ printf("Bad option format %s.\n", argv[i]);
+ return FALSE;
+ }
+ } else {
+ if (FoundEventText) {
+ printf("Bad parameter %s.\n", argv[i]);
+ return FALSE;
+ } else {
+ m_Text = argv[i];
+ FoundEventText = TRUE;
+ }
+ }
+ }
+
+ if ((!ShowUsage) && (!FoundEventText)) {
+ printf("The event text must be specified.\n");
+ return FALSE;
+ }
+
+ if (ShowUsage) {
+ Usage();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+ if (ParseCmdline(argc, argv))
+ WriteEvent ();
+
+ return 0;
+}
Added: trunk/rosapps/logevent/logevent.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/logevent/logevent.rbuild?r…
==============================================================================
--- trunk/rosapps/logevent/logevent.rbuild (added)
+++ trunk/rosapps/logevent/logevent.rbuild Sat Sep 8 12:31:56 2007
@@ -1,0 +1,9 @@
+<?xml version="1.0"?>
+
+<module name="logevent" type="win32cui"
installbase="system32" installname="logevent.exe"
allowwarnings="true">
+ <define name="__USE_W32API" />
+ <library>kernel32</library>
+ <library>advapi32</library>
+ <file>logevent.c</file>
+ <file>logevent.rc</file>
+</module>
Added: trunk/rosapps/logevent/logevent.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/logevent/logevent.rc?rev=2…
==============================================================================
--- trunk/rosapps/logevent/logevent.rc (added)
+++ trunk/rosapps/logevent/logevent.rc Sat Sep 8 12:31:56 2007
@@ -1,0 +1,5 @@
+#define REACTOS_STR_FILE_DESCRIPTION "Win32 logevent utility\0"
+#define REACTOS_STR_INTERNAL_NAME "logevent\0"
+#define REACTOS_STR_ORIGINAL_FILENAME "logevent.exe\0"
+
+#include <reactos/version.rc>