title: How do you get credentials (NetworkCredential) of currently logged in user?
body: <p>I'm writing some code to utilise a 3rd party component, and I need to supply an object which implements ICredentials when I start to use it.</p>
  
  <p>If I write the following...</p>
  
  <pre><code>var credential = new NetworkCredential("MyUsername", "MyPassword");
  </code></pre>
  
  <p>...and pass "credential", it's fine. But I would like to pass the credentials of the current user <em>(it's a Windows service, so runs as a specified user)</em>.</p>
  
  <p>I have tried both of the following, but neither appear to work <em>(or return anything)</em>:</p>
  
  <pre><code>NetworkCredential credential = System.Net.CredentialCache.DefaultCredentials;
  NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;
  </code></pre>
  
  <p>Can anyone suggest how to acquire an approriate object, which represents the credentials of the username that the service is running under ?</p>
  
  <p>Thanks</p>