I'm writing an app that aggregates all the event log entries on each of several different servers. I can get the event logs by passing in the MachineName
to EventLog.GetEventLogs
. This will typically fail at some stage is the user is not a local administrator on that machine, so I'd like to check for it ahead of time and skip to the next set of servers if that is the case
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
Most solutions, like the one here, only check if the user is an admin on the currently executing machine.
<!-- language: lang-vb -->Dim user As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As New WindowsPrincipal(user)
Dim isAdmin As Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)