<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.dervalp.com &#187; create</title>
	<atom:link href="http://blog.dervalp.com/tag/create/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dervalp.com</link>
	<description>Think before Programming (Public learning)</description>
	<lastBuildDate>Sat, 20 Mar 2010 22:22:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C#.NET Create users in Active Directory</title>
		<link>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/</link>
		<comments>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/#comments</comments>
		<pubDate>Sat, 23 May 2009 02:26:16 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Adsiedit]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=122</guid>
		<description><![CDATA[I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.
First, I decided to use the linq for Active Directory of Bart Desmet, I [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.</p>
<p>First, I decided to use the linq for Active Directory of <a href="http://community.bartdesmet.net/blogs/bart/Default.aspx">Bart Desmet</a>, I know it&#8217;s a pre-alpha version but we do not have a lot of time and I really want to use all the facilities you have when you developed with linq. <a href="http://www.codeplex.com/LINQtoAD">Here is the link</a>. If you used linq to Active Directory, you should have saw that you do not have method to create. Therefore, I decided to use linq to AD for the &#8220;get&#8221; method and the &#8220;classic&#8221; method for creating users.</p>
<p>If you want to create a user in Active Directory, you should follow theses steps :</p>
<p>1) Create the user</p>
<p>2) Set the user&#8217;s password</p>
<p>3) Activate the user</p>
<h2><span id="more-122"></span>1) Create the user in active directory :</h2>
<p>I work with the respository pattern for all the data access.  So I created an ActiveDirectoryRepository where I put all the main &#8220;get&#8221; method and the create, update and delete method.</p>
<p>Here bellow, you can see my code. I create a CreateUser function in which I pass an object ActiveDirectoryUser (custom object).</p>
<p>First I set the directory entry where I want to add my user. It is quite like a connection string. With this link, the application know where he has to make his job.</p>
<p>After, I set all the properties to make a User with some basic information (name, firstname, city, country,&#8230;). When everything is set, I commit the change to active directory.</p>
<p>When it&#8217;s done, I call the ActivePassword function and the ActiveUser function. If everything goes well and if you have not received an exception error, your user in now created in the active directory and can login with the password you set during the creation. Here &#8220;newpassword&#8221;. Of course it is only to show a basic example <img src='http://blog.dervalp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><img class="alignnone size-full wp-image-126" title="create_user_ad_1" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_1.png" alt="create_user_ad_1" width="801" height="585" /></p>
<p>Here under, the code for activate a user and set his password :</p>
<p><img class="alignnone size-full wp-image-127" title="create_user_ad_2" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_2.png" alt="create_user_ad_2" width="806" height="452" /></p>
<p>Why 512 for the userAccountControl ? 512 is the value for a normal account in the active directory. I hardcoded it in the function but of course you can easily make some function to manage the type of user you want to create. To know more about the different possible type of user account, click <a href="http://support.microsoft.com/kb/305144">here</a>.</p>
<p>For example, if you want to have an active user with a password which expires never. You have to know the value for an active user, 512 and the value for the option &#8220;DONT_EXPIRE_PASSWORD&#8221; 65536. You add the number 512 and 65536. So, 66048 is the right number for the properties userAccountControl in this case.</p>
<p>NOTE : If you read my post about managing adam or azam account, I spoke about the support tools for Windows 2003. In these tools, there is one very usefull for developers to know where they have to put the data in. The snap in Adsiedit.msc. It shows you if the thing you are searching is a OU, a CN,&#8230; I will post more details about this tool in another post.</p>
<p>This is the end for today, if you have questions or comments, do not hesitate to leave a comment.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d122" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+C%23.NET+Create+users+in+Active+Directory+@+http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;t=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
