Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Samples » Downloads
 
Add your own
alternative version

A small C# Class for impersonating a User

, 11 Apr 2005 CPOL
Introduced a class that simplifies Windows Impersonation in C#.
zetaimpersonator_demo.zip
ImpersonatorDemo
App.ico
bin
ImpersonatorDemo.csproj.user
using System;
using System.IO;
using Tools;

namespace ImpersonatorDemo
{
	/// <summary>
	/// Main class for the demo application.
	/// Call this application with a low privileg account to test.
	/// </summary>
	class Program
	{
		/// <summary>
		/// The main entry point.
		/// </summary>
		[STAThread]
		static void Main( string[] args )
		{
			// Impersonate, automatically release the impersonation.
			using ( new Impersonator( "yourUsername", "yourDomain", "yourPassword" ) )
			{
				// The following code is executed under the impersonated user.
				string[] files = Directory.GetFiles( "c:\\windows" );
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Offline-Homepage-Baukasten
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 11 Apr 2005
Article Copyright 2005 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid