<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Active Directory and LDAP</title><link>http://forums.asp.net/93.aspx</link><description>Questions about Active Directory and other directory stores, such as those accessible via LDAP, are appropriate here.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3266537.aspx</link><pubDate>Tue, 30 Jun 2009 12:44:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3266537</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3266537.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3266537</wfw:commentRss><description>&lt;p&gt;Actually I think I spoke to soon about fixing the issue :( &lt;br /&gt;&amp;nbsp;&lt;br /&gt;Something very wierd is&amp;nbsp;going on .... I have now tested several different user &amp;amp; group management functions, and some work and others don&amp;#39;t. Whether they work or not is affected by 2 things: (i) whether the SAM store on the same server as your ASP.NET app or on a remote server, and (ii) whether the machine/host name or machine IP address is specified in the PrincipalContext.&lt;/p&gt;
&lt;p&gt;Here are my findings. If anyone can explain this and suggest a solution I would be verrrry grateful.&lt;/p&gt;
&lt;p&gt;FYI, all functions were run through a PrincipalContext set up as follows:&lt;/p&gt;
&lt;p&gt;static PrincipalContext _PrincipalContext;&lt;br /&gt;_PrincipalContext = new PrincipalContext(ContextType.Machine, _WindowsServerName, null, &amp;quot;LocalAdminUsername&amp;quot;, &amp;quot;LocalAdminPassword&amp;quot;);&lt;/p&gt;
&lt;p&gt;The ASP.NET process was running under the regular (non-admin) NETWORK SERVICE acccount.&lt;/p&gt;
&lt;table class="mceItemTable" cellspacing="0" cellpadding="2"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;
&lt;p&gt;&lt;b&gt;SAM store on the same server as your ASP.NET app&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;
&lt;p&gt;&lt;b&gt;SAM store on a remote server from your ASP.NET app&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Function&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;machine name in the PrincipalContext&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;machine&amp;nbsp;IP address&amp;nbsp;in the PrincipalContext&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;host name in the PrincipalContext (name set up in Hosts file)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;machine&amp;nbsp;IP address&amp;nbsp;in the PrincipalContext&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Creating a user&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&amp;quot;General access denied” * error&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Checking if a user exists&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Checking if a group exists&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Checking if a user is in a group&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;always returns false&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;always returns false&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Adding a user to a group&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Removing a user from a group&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&amp;quot;General access denied” ** error&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;does not error, but no change is made&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;does not error, but no change is made&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Deleting a user&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&amp;quot;General access denied” *** error&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Disabling &amp;amp; re-enabling a user&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&amp;quot;General access denied” **** error&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Setting user password&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&amp;quot;Exception thrown” ***** error&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;OK&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;* General access denied error ---&amp;gt; System.UnauthorizedAccessException: General access denied error at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.SetInfo() at System.DirectoryServices.DirectoryEntry.CommitChanges() at System.DirectoryServices.AccountManagement.SDSUtils.ApplyChangesToDirectory(Principal p, StoreCtx storeCtx, GroupMembershipUpdater updateGroupMembership, NetCred credentials, AuthenticationTypes authTypes) at System.DirectoryServices.AccountManagement.SDSUtils.InsertPrincipal(Principal p, StoreCtx storeCtx, GroupMembershipUpdater updateGroupMembership, NetCred credentials, AuthenticationTypes authTypes, Boolean needToSetPassword) at System.DirectoryServices.AccountManagement.SAMStoreCtx.Insert(Principal p) at System.DirectoryServices.AccountManagement.Principal.Save()&lt;/p&gt;
&lt;p&gt;** General access denied error ---&amp;gt; at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsGroup.Remove(String bstrItemToBeRemoved) at System.DirectoryServices.AccountManagement.SAMStoreCtx.UpdateGroupMembership(Principal group, DirectoryEntry de, NetCred credentials, AuthenticationTypes authTypes) at System.DirectoryServices.AccountManagement.SDSUtils.ApplyChangesToDirectory(Principal p, St&lt;/p&gt;
&lt;p&gt;*** General access denied error ---&amp;gt; at System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsContainer.Delete(String className, String relativeName) at System.DirectoryServices.DirectoryEntries.Remove(DirectoryEntry entry) at System.DirectoryServices.AccountManagement.SDSUtils.DeleteDirectoryEntry(DirectoryEntry deToDelete) at System.DirectoryServices.AccountManagement.SAMStoreCtx.Delete(Principal p)&lt;/p&gt;
&lt;p&gt;**** General access denied error ---&amp;gt; at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.SetInfo() at System.DirectoryServices.DirectoryEntry.CommitChanges() at System.DirectoryServices.AccountManagement.SDSUtils.ApplyChangesToDirectory(Principal p, StoreCtx storeCtx, GroupMembershipUpdater updateGroupMembership, NetCred credentials, AuthenticationTypes authTypes)&lt;/p&gt;
&lt;p&gt;***** Exception has been thrown by the target of an invocation. ---&amp;gt; at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) at System.DirectoryServices.AccountManagement.SDSUtils.SetPassword(DirectoryEntry de, String newPassword) at System.DirectoryServices.AccountManagement.SAMStoreCtx.SetPassword(AuthenticablePrincipal p, String newPassword)&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3257445.aspx</link><pubDate>Thu, 25 Jun 2009 10:20:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3257445</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3257445.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3257445</wfw:commentRss><description>&lt;p&gt;One other thing I found out, which might help someone:&lt;/p&gt;
&lt;p&gt;If the machine name is set to an IP address in the PrincipalContext, some functions (like creating a user) work, but others don&amp;#39;t (like finding out if a user is in a group).&lt;/p&gt;
&lt;p&gt;For example, the following always returns false (even though the user1 and group1 objects are found):&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;font size="2"&gt;
&lt;p&gt;UserPrincipal user1 &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; UserPrincipal&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;FindByIdentity&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;_PrimaryPrincipalContext&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; IdentityType&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;SamAccountName&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; username&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&amp;nbsp;GroupPrincipal group1 &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; GroupPrincipal&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;FindByIdentity&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;_PrimaryPrincipalContext&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; IdentityType&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;SamAccountName&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;,&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; groupname&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;/p&gt;
&lt;p&gt;if&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;user1 &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;!=&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;amp;&amp;amp;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; group1 &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;!=&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;null)&lt;/font&gt;&lt;/font&gt;
&lt;p&gt;&lt;font size="2"&gt; &lt;/p&gt;
&lt;p&gt;{&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; user1&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;IsMemberOf&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;group1&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3257408.aspx</link><pubDate>Thu, 25 Jun 2009 10:03:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3257408</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3257408.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3257408</wfw:commentRss><description>&lt;p&gt;After weeks of frustration I finally found out that there was nothing wrong with my original code. It seems there is something &amp;quot;wrong&amp;quot; with my Windows XP dev machine. At least when I ran the same code on another XP machine and on a Win 2003 server it worked fine. What exactly is wrong with my machine I don&amp;#39;t know. The problem in a nutshell is that, even though a username &amp;amp; pwd are specified in the PrincipalContext to connect to the local machine&amp;#39;s security store with, and that user is an administrator, they are not used and the ASP.NET security context (ASPNET user on Win XP) is used instead.&lt;/p&gt;
&lt;p&gt;Minor point of interest - in my original post I said that even when I made the ASPNET user an administrator it still couldn&amp;#39;t create users. Actually this does work, it just doesn&amp;#39;t come into effect immediately you promote the ASPNET user. Not sure what got it to work, maybe restarting the machine, maybe restarting IIS or the worker process.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the code I am now using:&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;
&lt;p&gt;
&lt;p&gt;static PrincipalContext _PrimaryPrincipalContext;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;
&lt;p&gt;_PrimaryPrincipalContext = new PrincipalContext(ContextType.Machine, _PrimaryWindowsServerName, null, &amp;quot;Username&amp;quot;, &amp;quot;Password&amp;quot;);&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;UserPrincipal user = UserPrincipal.FindByIdentity(_PrimaryPrincipalContext, IdentityType.SamAccountName, username);&lt;br /&gt;if (user != null)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LogEntry(&amp;quot;CreateUserAccount&amp;quot;, &amp;quot;Windows user: &amp;quot; + username + &amp;quot; already exists on server: &amp;quot; + _PrimaryWindowsServerName);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user = new UserPrincipal(_PrimaryPrincipalContext);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.Name = username;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.DisplayName = name;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.Description = description;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.SetPassword(password);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.Enabled = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.UserCannotChangePassword = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.PasswordNeverExpires = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user.Save();&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3158025.aspx</link><pubDate>Tue, 12 May 2009 17:35:46 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3158025</guid><dc:creator>sumitd</dc:creator><author>sumitd</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3158025.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3158025</wfw:commentRss><description>&lt;p&gt;Refer below urls, it might help you:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thejackol.com/2004/08/03/create-a-local-windows-user-account-cnet/"&gt;http://www.thejackol.com/2004/08/03/create-a-local-windows-user-account-cnet/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb299773.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb299773.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/system/everythingInAD.aspx?fid=399045&amp;amp;df=90&amp;amp;mpp=25&amp;amp;noise=3&amp;amp;sort=Position&amp;amp;view=Quick&amp;amp;select=2946181"&gt;http://www.codeproject.com/KB/system/everythingInAD.aspx?fid=399045&amp;amp;df=90&amp;amp;mpp=25&amp;amp;noise=3&amp;amp;sort=Position&amp;amp;view=Quick&amp;amp;select=2946181&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Refer below discussion:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://objectmix.com/csharp/356216-create-windows-account-programmatically-c.html"&gt;http://objectmix.com/csharp/356216-create-windows-account-programmatically-c.html&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3157993.aspx</link><pubDate>Tue, 12 May 2009 17:12:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3157993</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3157993.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3157993</wfw:commentRss><description>&lt;p&gt;Thanks for the replies but noone seems to have understood the problem. I am trying to create accounts on the LOCAL server. There is no Active Directory involved, so there is no Windows Authorization Access group.&lt;/p&gt;
&lt;p&gt;Also, it is my understanding that the ASP.NET code runs in the context of the local ASPNET account (on XP) or NETWORK SERVICE (on Win 2003), so that is the account that needs to be given permission to create accounts (not Anonymous Login or anything like that).&lt;/p&gt;
&lt;p&gt;It seems like a u/n &amp;amp; pwd can be specified in the PrincipalContext for interacting with the security accounts system, but as I said in 1st post I can&amp;#39;t get this to work.&lt;/p&gt;
&lt;p&gt;Does anyone know how the System.DirectoryServices.AccountManagement objects can be used to create a LOCAL account through ASP.NET?&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3132245.aspx</link><pubDate>Fri, 01 May 2009 05:17:06 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3132245</guid><dc:creator>sumitd</dc:creator><author>sumitd</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3132245.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3132245</wfw:commentRss><description>&lt;p&gt;You need to add Anonymous Logon to Windows Authorization Access group of the Active Directory to work with anonymous acess.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3131673.aspx</link><pubDate>Thu, 30 Apr 2009 20:57:10 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3131673</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3131673.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3131673</wfw:commentRss><description>&lt;p&gt;I can&amp;#39;t uncheck anonymous access in IIS. The site needs to be available to anonymous users.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3131230.aspx</link><pubDate>Thu, 30 Apr 2009 17:08:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3131230</guid><dc:creator>sumitd</dc:creator><author>sumitd</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3131230.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3131230</wfw:commentRss><description>&lt;p&gt;Have you unchecked anonymous access in IIS, only windows integrated should be checked.&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3131217.aspx</link><pubDate>Thu, 30 Apr 2009 17:01:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3131217</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3131217.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3131217</wfw:commentRss><description>&lt;p&gt;I read the article but it doesn&amp;#39;t help. It talks about specifying the right container, but that applies only to creating accounts in Active Directory. In my case I am creating an account on the local machine and the MS documentation says that in that case Container should be Null. Just in case I tried setting the Container parameter to Null in the PrincipalContext creation but it made no difference.&lt;/p&gt;&lt;pre class="coloredcode"&gt;PrincipalContext context = &lt;span class="kwd"&gt;new&lt;/span&gt; PrincipalContext(ContextType.Machine, PrimaryWindowsServer, &lt;span class="kwd"&gt;null&lt;/span&gt;, &lt;span class="st"&gt;&amp;quot;HostUser&amp;quot;&lt;/span&gt;, &lt;span class="st"&gt;&amp;quot;HostPassword&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also tried creating a Console app running the same function. I got the same error when running the app as a regular user. However when running the app as an administrator the function worked. This tells me that the u/n &amp;amp; pwd specified in the PrincipalContext creation are not used as the security context for my function. So what are they for??&lt;/p&gt;
&lt;p&gt;I really want to be able to specify a u/n &amp;amp; pwd in code and not have to configure the accounts the web app runs under.&lt;/p&gt;
&lt;p&gt;Any more ideas?&lt;/p&gt;</description></item><item><title>Re: General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3131155.aspx</link><pubDate>Thu, 30 Apr 2009 16:36:01 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3131155</guid><dc:creator>sumitd</dc:creator><author>sumitd</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3131155.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3131155</wfw:commentRss><description>&lt;p&gt;Refer below discussion, discussion is bit long though:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.keyongtech.com/5024690-access-denied-when-userprincipal-save"&gt;http://www.keyongtech.com/5024690-access-denied-when-userprincipal-save&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>General access denied error creating user on local machine, but running as administrator</title><link>http://forums.asp.net/thread/3131091.aspx</link><pubDate>Thu, 30 Apr 2009 16:05:24 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3131091</guid><dc:creator>lneville</dc:creator><author>lneville</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3131091.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=93&amp;PostID=3131091</wfw:commentRss><description>&lt;p&gt;I have a function to create a local user in the web server that my .NET site is running on. I am using System.DirectoryServices.AccountManagement. I get the following&amp;nbsp;error every time I call Save on the new UserPrinciple object:&lt;/p&gt;
&lt;p&gt;General access denied error ---&amp;gt; System.UnauthorizedAccessException: General access denied error at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.SetInfo() at System.DirectoryServices.DirectoryEntry.CommitChanges() at System.DirectoryServices.AccountManagement.SDSUtils.ApplyChangesToDirectory(Principal p, StoreCtx storeCtx, GroupMembershipUpdater updateGroupMembership, NetCred credentials, AuthenticationTypes authTypes) at System.DirectoryServices.AccountManagement.SDSUtils.InsertPrincipal(Principal p, StoreCtx storeCtx, GroupMembershipUpdater updateGroupMembership, NetCred credentials, AuthenticationTypes authTypes, Boolean needToSetPassword) at System.DirectoryServices.AccountManagement.SAMStoreCtx.Insert(Principal p) at System.DirectoryServices.AccountManagement.Principal.Save()&lt;/p&gt;
&lt;p&gt;I am developing on WinXP/IIS5. I have tried putting my ASPNET account in the Administrators group. I have tried specifying an administrator u/n &amp;amp; pwd in the PrincipalContext. Both cases produce this error. I can&amp;#39;t use Impersonation in the web.config for various reasons.&lt;/p&gt;
&lt;p&gt;Here is my function.&lt;/p&gt;&lt;pre class="coloredcode"&gt;        &lt;span class="kwd"&gt;public void&lt;/span&gt; CreateUserAccount(&lt;span class="kwd"&gt;string&lt;/span&gt; username, &lt;span class="kwd"&gt;string&lt;/span&gt; password)
        {
            PrincipalContext context = &lt;span class="kwd"&gt;new&lt;/span&gt; PrincipalContext(ContextType.Machine, PrimaryWindowsServer, &lt;span class="st"&gt;&amp;quot;HostUser&amp;quot;&lt;/span&gt;, &lt;span class="st"&gt;&amp;quot;HostPassword&amp;quot;&lt;/span&gt;);

            UserPrincipal up = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
            &lt;span class="kwd"&gt;if&lt;/span&gt; (up != &lt;span class="kwd"&gt;null&lt;/span&gt;)
            {
                LogEntry(&lt;span class="st"&gt;&amp;quot;CreateUser&amp;quot;&lt;/span&gt;, username + &lt;span class="st"&gt;&amp;quot; already exists&amp;quot;&lt;/span&gt;);
            }
            &lt;span class="kwd"&gt;else&lt;/span&gt;
            {
                up = &lt;span class="kwd"&gt;new&lt;/span&gt; UserPrincipal(context);
                up.Name = username;
                up.SetPassword(password);
                up.Enabled = &lt;span class="kwd"&gt;true&lt;/span&gt;;
                up.UserCannotChangePassword = &lt;span class="kwd"&gt;true&lt;/span&gt;;
                up.Save();
            }
        }&lt;/pre&gt;&amp;nbsp;What am I doing wrong?&lt;br /&gt;</description></item></channel></rss>