-1

my task: I want to display entries from the windows eventlog from my printjobs. I found various tutorials from msdn and different sites, but I cannot get access to my preferred protocol/service name.

Microsoft-Windows-PrintService

    my Code ( c#): 
 string lists = EventLog.LogNameFromSourceName("Microsoft-Windows-PrintService/Operational", ".");

but this code is not working. Did somebody know a solution or a workaround for my problem. This is my first project in c#.

Thanks in Advance!

Developer2as
  • 85
  • 1
  • 1
  • 8

2 Answers2

0

Your syntax for the call is correct. I think the source you are specifying in the call probably doesn't exist.

If you call EventLog.SourcesExists("Microsoft-Windows-PrintService/Operational") does it return false? If so, then the source string you are passing is incorrect and you need to find the correct source from Event Viewer.

Edit: In response to your later post, I don't think permissions have anything to do with it. I was able to access "Application and Services Logs" sources without doing anything special.

According to this previous post event log sources cannot be listed from the API but must be mined from the registry. However, I did find an application EventLogSourcesView that can generate a list of all event sources. It may be helpful in finding the source you are looking for.

Good luck!

Community
  • 1
  • 1
Don Sealy
  • 16
  • 4
  • thanks for your help! I can not identify the right path to the events log, but I take an other way to fetch the print jobs ( Actually, I read the jobs with WMI) . but thank´s for all hints! – Developer2as Feb 06 '16 at 14:14
0

thanks for your reply.

Yes, the SourceExist Method return false. Hmm.. I have no idea how to find the correct Service name.

The SoruceExist Method returns true, for all protocols which are listed under the "Windows Protocols"-section, only. The other protocols which are located under the section "Anwendungs- und Dienstprotokolle" ( I use a german windows version - maybe translate to "Application-and Serviceprotocols"), the method returns false.

In this location, the log will be saved at

 %SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-PrintService%4Operational.evtx

Did I need special permissons to "enter" these logs ( Currently, Visual Studio is started as Administrator, only .. enough?)

Thanks!

Developer2as
  • 85
  • 1
  • 1
  • 8