How do you get credentials (NetworkCredential) of currently logged in user ?

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-02-23T16:08:51Z Indexed on 2010/04/10 0:53 UTC
Read the original article Hit count: 580

Hi,

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.

If I write the following...

var credential = new NetworkCredential("MyUsername", "MyPassword");

...and pass "credential", it's fine. But I would like to pass the credentials of the current user (it's a Windows service, so runs as a specified user).

I have tried both of the following, but neither appear to work (or return anything):

NetworkCredential credential = System.Net.CredentialCache.DefaultCredentials;
NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;

Can anyone suggest how to acquire an approriate object, which represents the credentials of the username that the service is running under ?

Thanks, Ross

© Stack Overflow or respective owner

Related posts about defaultnetworkcredentials