我正在编写一个应用程序来聚合几个不同服务器中的每一个上的所有事件日志条目。MachineName
我可以通过传入to来获取事件日志EventLog.GetEventLogs
。如果用户不是该机器上的本地管理员,这通常会在某个阶段失败,所以我想提前检查一下,如果是这种情况,请跳到下一组服务器
For Each svr As String In Servers
'TODO: check to see if they are a local administrator, else continue for
Dim logs As List(Of EventLog) = EventLog.GetEventLogs(svr).ToList
For Each log As EventLog In logs
LoadEachOSLogEntry(log)
Next
Next
大多数解决方案,比如这里的解决方案,只检查用户是否是当前执行机器上的管理员。
Dim user As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As New WindowsPrincipal(user)
Dim isAdmin As Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)