Impersonate - accessing a network folder from .NET

Thursday, 8 May 2008 09:22 by Myself

This is and neat class I've put together that allows you to specify username and password (and optionally a domain) and act under that identity. Primarily to access a shared folder, but you could easily find more areas of use.

   1: using (new Impersonator(true, "username", "password", "123.123.123.123"))
   2: {
   3:     // The new idenity is only active inside this using clause
   4:     if (!Directory.Exists(@"\\123.123.123.123\Foo\bar"))
   5:         Directory.CreateDirectory(@"\\123.123.123.123\Foo\bar");
   6: } 
   7:  

It makes use of the Win32 API "LogonUser".

Download the source code and give it a try!

Impersonator.7z (3.60 kb)

Tags:   ,
Categories:   Development
Actions:   E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 22. 2008 04:10

 
Software