[EVENTLOG]
authorEric Kohl <eric.kohl@reactos.org>
Tue, 10 May 2011 20:19:14 +0000 (20:19 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 10 May 2011 20:19:14 +0000 (20:19 +0000)
Log product info upon startup.

svn path=/trunk/; revision=51670

reactos/base/services/eventlog/eventlog.c
reactos/base/services/eventlog/eventlog.h
reactos/base/services/eventlog/file.c

index ee34a1d..d0ee12f 100644 (file)
@@ -135,6 +135,71 @@ ServiceInit(VOID)
 }
 
 
+static VOID
+ReportProductInfoEvent(VOID)
+{
+    OSVERSIONINFOW versionInfo;
+    WCHAR szBuffer[512];
+    DWORD dwLength;
+    HKEY hKey;
+    DWORD dwValueLength;
+    DWORD dwType;
+    LONG lResult = ERROR_SUCCESS;
+
+    ZeroMemory(&versionInfo, sizeof(OSVERSIONINFO));
+    versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+    /* Get version information */
+    if (!GetVersionExW(&versionInfo))
+        return;
+
+    ZeroMemory(szBuffer, 512 * sizeof(WCHAR));
+
+    /* Write version into the buffer */
+    dwLength = swprintf(szBuffer,
+                        L"%lu.%lu",
+                        versionInfo.dwMajorVersion,
+                        versionInfo.dwMinorVersion) + 1;
+
+    /* Write build number into the buffer */
+    dwLength += swprintf(&szBuffer[dwLength],
+                         L"%lu",
+                         versionInfo.dwBuildNumber) + 1;
+
+    /* Write service pack info into the buffer */
+    wcscpy(&szBuffer[dwLength], versionInfo.szCSDVersion);
+    dwLength += wcslen(versionInfo.szCSDVersion) + 1;
+
+    /* Read 'CurrentType' from the registry and write it into the buffer */
+    lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                           L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
+                           0,
+                           KEY_QUERY_VALUE,
+                           &hKey);
+    if (lResult == ERROR_SUCCESS)
+    {
+        dwValueLength = 512 - dwLength;
+        lResult = RegQueryValueEx(hKey,
+                                  L"CurrentType",
+                                  NULL,
+                                  &dwType,
+                                  (LPBYTE)&szBuffer[dwLength],
+                                  &dwValueLength);
+
+        RegCloseKey(hKey);
+    }
+
+    /* Log the product information */
+    LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
+                    0,
+                    EVENT_EventLogProductInfo,
+                    4,
+                    szBuffer,
+                    0,
+                    NULL);
+}
+
+
 static VOID CALLBACK
 ServiceMain(DWORD argc,
             LPWSTR *argv)
@@ -169,9 +234,15 @@ ServiceMain(DWORD argc,
         DPRINT("Service started\n");
         UpdateServiceStatus(SERVICE_RUNNING);
 
+        ReportProductInfoEvent();
+
         LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
                         0,
-                        EVENT_EventlogStarted);
+                        EVENT_EventlogStarted,
+                        0,
+                        NULL,
+                        0,
+                        NULL);
     }
 
     DPRINT("ServiceMain() done\n");
index 2ed6a4f..f4db6a3 100644 (file)
@@ -12,6 +12,7 @@
 #define NDEBUG
 #define WIN32_NO_STATUS
 
+#include <stdio.h>
 #include <windows.h>
 #include <netevent.h>
 #include <lpctypes.h>
@@ -181,7 +182,11 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
 VOID
 LogfReportEvent(WORD wType,
                 WORD wCategory,
-                DWORD dwEventId);
+                DWORD dwEventId,
+                WORD wNumStrings,
+                WCHAR *lpStrings,
+                DWORD dwDataSize,
+                LPVOID lpRawData);
 
 /* eventlog.c */
 extern HANDLE MyHeap;
index 3dd38af..116d0d0 100644 (file)
@@ -1054,7 +1054,11 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
 VOID
 LogfReportEvent(WORD wType,
                 WORD wCategory,
-                DWORD dwEventId)
+                DWORD dwEventId,
+                WORD wNumStrings,
+                WCHAR *lpStrings,
+                DWORD dwDataSize,
+                LPVOID lpRawData)
 {
     WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
     DWORD dwComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
@@ -1086,10 +1090,10 @@ LogfReportEvent(WORD wType,
                                            (LPCWSTR)szComputerName,
                                            0,
                                            NULL,
-                                           0, //wNumStrings,
-                                           NULL, //lpStrings,
-                                           0, //dwDataSize,
-                                           NULL); //lpRawData);
+                                           wNumStrings,
+                                           lpStrings,
+                                           dwDataSize,
+                                           lpRawData);
 
     dwError = LogfWriteData(pEventSource->LogFile, recSize, logBuffer);
     if (!dwError)