Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 332
Black Light Avatar asked Feb 23 '10 16:02

Black Light


People also ask

What are Default network credentials?

For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.


1 Answers

have you tried WindowsIdentity.GetCurrent()?

you could also look at this example... http://www.codeproject.com/KB/vb/Windows_Service.aspx

like image 63
yamspog Avatar answered Sep 25 '22 01:09

yamspog