Write to Windows event log: Difference between revisions
Content added Content deleted
(fixed sub-headers.) |
(Added C implementation.) |
||
Line 230: | Line 230: | ||
PROC_comexit</lang> |
PROC_comexit</lang> |
||
=={{header|C}} |
|||
The following is a wrapper on the EventCreate utility provided in Windows. Note that to use this wrapper, the code must be executed from a console/IDE running as Administrator. The utility itself does extensive error-checking and validation, so apart from the check that 5 arguments have been supplied, no other validations or checks are performed. |
|||
<lang C> |
|||
/*Abhishek Ghosh, 6th October 2017*/ |
|||
#include<stdlib.h> |
|||
#include<stdio.h> |
|||
int main(int argC,char* argV[]) |
|||
{ |
|||
char str[1000]; |
|||
if(argC!=5) |
|||
printf("Usage : %s < Followed by level, id, source string and description>",argV[0]); |
|||
else{ |
|||
sprintf(str,"EventCreate /t %s /id %s /l APPLICATION /so %s /d \"%s\"",argV[1],argV[2],argV[3],argV[4]); |
|||
system(str); |
|||
} |
|||
return 0; |
|||
} |
|||
</lang> |
|||
Invocation and output on console : |
|||
<pre> |
|||
C:\rosettaCode>eventLog.exe WARNING 458 SOmeString "This is a joke" |
|||
SUCCESS: An event of type 'WARNING' was created in the 'APPLICATION' log with 'SOmeString' as the source. |
|||
</pre> |
|||
Microsoft does provide an C/C++ API for EventCreate, but as with everything Microsoft, it's so wonderfully convoluted, that I will just give a link to the [https://msdn.microsoft.com/en-us/library/aa363680(v=vs.85).aspx ReportEvent] example. |
|||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
In Windows Vista and later or Windows Server 2003, you must have administrative privileges to execute this code. |
In Windows Vista and later or Windows Server 2003, you must have administrative privileges to execute this code. |