title: Check if user is a local admin on external machine
body: <p>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 <code>MachineName</code> to <code>EventLog.GetEventLogs</code>.  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</p>
  
  <pre class="lang-vb prettyprint-override"><code>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
  </code></pre>
  
  <p>Most solutions, like the one <a href="https://stackoverflow.com/questions/1089046/in-net-c-test-if-user-is-an-administrative-user">here</a>, only check if the user is an admin on the currently executing machine.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim user As WindowsIdentity = WindowsIdentity.GetCurrent()
  Dim principal As New WindowsPrincipal(user)
  Dim isAdmin As Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)
  </code></pre>