使用c#从事件查看器获取最新的Windows Startup登录事件数据?

问题描述:

我从Windows安全日志和事件查看器获取有关登录和注销的所有信息,但我只想从所有信息中获取最新的对数事件信息,请将一些LINQ应用于该事件以获取最多的Startup Login事件信息使用c#从事件查看器获取最新的Windows Startup登录事件数据?

这里是我的代码我试图

 EventLog log = new EventLog() 
     { 
      Source = "Microsoft Windows security auditing.", 
      Log = "Security" 
     }; 
     foreach (EventLogEntry entry in log.Entries) 
     { 

      Console.WriteLine(entry.Message); 
     } 

,你可以做任何的foreach拉姆达基地得到的只有登录事件是最新的一个

+1

最新的事件总是:'log.Entries [log.Entries.Count - 1];'。你不需要foreach, – 2016-07-16 09:25:15

+0

,但只有登录其注销 –

下面是一个样本,以获得最新的“登录( 4624)“和”特殊登录(4672)“

var log = new EventLog 
    { 
    Source = "Microsoft Windows security auditing.", 
    Log = "Security" 
    }; 
    var latestLogon = 
    log.Entries.Cast<EventLogEntry>() 
     .Where(entry => entry.InstanceId == 4624 || entry.InstanceId == 4672) 
     .OrderByDescending(i => i.TimeWritten) 
     .FirstOrDefault(); 
+0

你有一个LINK如何启动服务自动启动登录C# –

+0

也许这一个:http://*.com/questions/ 1477618 /我怎么做,我改变一个Windows服务启动类型在网络安装后 – 2016-07-16 10:25:47

+0

做到了它[启动服务赢得登录链接](http://*.com/questions/ 5089601/run-the-application-at-windows-startup) –