MCPcopy Create free account
hub / github.com/mhammond/pywin32 / CheckRegisterEventSourceFile

Function CheckRegisterEventSourceFile

win32/src/PythonService.cpp:1436–1472  ·  view source on GitHub ↗

register the event source with the event log.

Source from the content-addressed store, hash-verified

1434
1435// register the event source with the event log.
1436static void CheckRegisterEventSourceFile()
1437{
1438 // ignore all failures when setting up - for whatever reason it fails,
1439 // we are probably still better off calling ReportEvent than
1440 // not calling due to some other failure here.
1441 if (g_bRegisteredEventSource)
1442 return;
1443
1444 if (!g_szEventSourceFileName[0])
1445 GetModuleFileName(g_hdll, g_szEventSourceFileName,
1446 sizeof g_szEventSourceFileName/sizeof TCHAR);
1447
1448 HKEY hkey;
1449 TCHAR keyName[MAX_PATH];
1450
1451 _tcscpy(keyName, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\"));
1452 _tcscat(keyName, g_szEventSourceName );
1453
1454 BOOL rc = FALSE;
1455 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
1456 keyName,
1457 0,
1458 NULL,
1459 REG_OPTION_NON_VOLATILE,
1460 KEY_WRITE, NULL,
1461 &hkey,
1462 NULL) == ERROR_SUCCESS) {
1463 RegSetValueEx(hkey, TEXT("EventMessageFile"), 0, REG_SZ,
1464 (const BYTE *)g_szEventSourceFileName,
1465 (_tcslen(g_szEventSourceFileName)+1)*sizeof(TCHAR));
1466 DWORD types = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
1467 RegSetValueEx(hkey, TEXT("TypesSupported"), 0, REG_DWORD,
1468 (const BYTE *)&types, sizeof(types));
1469 RegCloseKey(hkey);
1470 }
1471 g_bRegisteredEventSource = TRUE;
1472}
1473
1474static BOOL ReportError(DWORD code, LPCTSTR *inserts, WORD errorType /* = EVENTLOG_ERROR_TYPE*/)
1475{

Callers 2

PySetEventSourceNameFunction · 0.70
ReportErrorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected