.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

System.DirectoryService.AccountManagement Creating Local Profiles

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net

Hello all!

I have a block of code that changes a users password as they enter it.  It appears that when they do this, it creates a local profile on the Windows 2008 Server for that user.  I'm doing it as follows...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices.AccountManagement;
using System.Web.Hosting;
using System.Security;
using System.Security.Principal;
using System.DirectoryServices;

namespace ActiveDirectoryTools
    internal class ADProfileMgmt
        PrincipalContext context;
        DirectoryEntry _entry = new DirectoryEntry();

        internal ADProfileMgmt(string domainName, string userName, string password)
            context = new PrincipalContext(ContextType.Domain, domainName, userName, password);

        internal UserPrincipal SearchUser(string userName)
                UserPrincipal user = new UserPrincipal(context);
                user = UserPrincipal.FindByIdentity(context, userName);

                return user;    

        internal void ChangePassword(string userName, string oldPassword, string newPassword)
            UserPrincipal user = SearchUser(userName);

            user.ChangePassword(oldPassword, newPassword);


View Complete Post

More Related Resource Links

System.DirectoryServices.AccountManagement: FileNotFound exception while creating PrincipalContext o

Hi, I want to create a local group for my Netapp server. And also add a domain user under this group. Using .NET namepaces System.DirectoryServices.AccountManagement, I can achive this for Windows server. But if the same code is tried on NetApp, following exception is thrown: Unhandled Exception: System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)   at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo()   at System.DirectoryServices.DirectoryEntry.RefreshCache()   at System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit()   at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()   at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()    at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue)   at System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, String identityValue)   at AddGroup.Program.Main(String[] args) Does S

smtp is noe sending email instantly,it makes a Queue in my local system

I am using a  smtp to send email from asp.net (C#)code.it sending some email instantly but many of email is making a queue in my Inetpub folder at local system.what could be the issue ? please help me to get rid from it.ThankxArvind

Can´t set up local system accounts as service accounts in sharepoint 2010

HI I made an inplace upgrade to sharepoint 2010. I want to setup performance point services. but it doesn´t allow me to set a local system account as the application pool account for performance point services application. It doesn´t allow me to register a new account it says The specified user account "domain\username" is a local account. Local accounts should only be used in stand alone mode. The application pool account for the site collection that I upgraded is a local system account so I don´t get it? I tried this http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=112 However the upgrade fails after this. Is there any way that I do the inplace upgrade and it would allow me to use local system accounts has service accounts? Without Active directory? Thanks      

SQL Error with Login: Login failed for user 'NT AUTHORITY\SYSTEM'. [CLIENT: ]

<!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 3.0cm 70.85pt 3.0cm; mso-header-m

Creating assembly throwing an error as system.directoryservices assembly is not in the SQL Server

Hi, I am trying to create an assembly (DLL file that created by C# ) which uses System.DirectoryServices assembly. When I try with following script Create ASSEMBLY Addresstype From 'C:\ActiDirectoryFunctions\ActiveDirectoryFunctions.dll' I am getting following Error Assembly 'ActiveDirectoryFunctions' references assembly 'system.directoryservices, version=, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request. From above error message, I learnt that System.DirectoryServices assembly is not in the SQL Server. I am using SQL SERVER 2005 SP2 and .Net Framework 3 is there in the machine How to manually add this assembly into this SQL Server Machine? Please let me know if you know Thank you, Raj Dreaming a world without any war in anywhere

Access Denied creating a web application in SP Foundation 2010 installed on windows 7 with local acc



I've installed SharePoint foundation over windows 7 with a local account using this guide: http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=112

When I try to create a new web application the ribbon button is disabled. Using the link located in /_admin/createsite.aspx I get an "Access Denied" error message.

I access the SP Administration with the same user used during installation. This user is local admin and member of SQL server roles "securityadmin" and "dbcreator".

Any idea about this error?


Thanks in advance

Creating local user account in Sharepoint 2010



I need to create a few account in Sharepoint 2010 that don't belong to the active directory import. I have logged on to the Sharepoint server and created the accounts and expected them to appear when I went to Site Settings and then people and groups and searched for the account names.

I did the same in 2007 and these still appear as the machinename/username.

Is there something I don't know about?


Downloading a document from a sharepoint site to local file system, copy web service returns null

Hi Guys,
               I am trying to get this done for the last 2 days and I am still banging my head to the wall.
All I need to do is to download files from my sharepoint site library that uses integrated windows authentication. I was using copy webservice : getItem method to accomplish this.

CopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

Problem : myByteArray is always returned as NULL

Note: I have tried the same with another site that uses forms authentication but the result was the same (NULL !!)

This is my code:


Copy copy = new CopyService.Copy();


inequality search with System.DirectoryServices.AccountManagement.PrincipalSearcher?


The System.DirectoryServices.AccountManagement are a great time-saver when working with Active Directory!  But now I'm stuck.

Is it possible to use inequality searches with PrincipalSearcher?  For instance, i have users with three types:


and possibly more.  I want only non-Foo users.  With PrincipalSearcher's underlying DirectorySearcher, i could give it a string filter like this:


With PrincipalSearcher, that inequality doesn't seem to be possible!  I've searched all through MSDN articles and haven't found anything that covers this.

Any help is appreciated!

Creating Local cube on Cube using Many-to-Many dimension relationship


Hi All,

I have got a cube that uses many-to-many dimensions relationship. I also have a calculated measure (A*B) in the measure group using a unary operator.

I tried creating the local cube by using CREATE GLOBAL CUBE statement and included the intermediate measure group and one measure from the group. I have also included all the dimensions that are linked to the intermediate measure group.

The local cube is being created but I don't see the correct values of the measures. I just get the value of A coming for the value of the calculated measures. There are also some performance issues while browsing the local cube which I assumed should be very fast.

I am not sure if this is a known issue and there's a solution available for this but I tried and didn't find anything on the forum. 

Please help me with this. Thanks in Advance.


Creating Local cube file using ASSL


Hi All,

I am looking to create a local cube by using ASSL. I didn't find much help on this. Please brief me the steps on how to create the local cube file using ASSL.

Thanks in Advance.

Creating DSN for local machine in SQL Server Express 2005


Good evening,

This is my first time with SQL Server, so please forgive me if this is a ridiculous question:

I'm trying to create a DSN so I can connect up to SQL Server Express 2005 on my laptop/local machine. I'm attempting to connect via Windows NT authentication. I've tried 'Named Pipes' and TCP/IP settings but am not able to connect. I keep getting an error that states:

SQLState: '01000'

SQL Server Error: 2

Connection failed

SQLState: '08001'

SQL Server Error: 17

SQL Server does not exist or access denied

Is the server created by just installing SQL Server 2005, or is there something additional I need to do? Any help would be much appreciated.




Regarding backup of database to public ip system from local system



how to take backup of database from local system to public ip system?

Database on local system..

that backup file should be on that public ip system..

Please help me ASAP

Thanks in advance.

Creating a new system with WF 4.0


It seems unlcear to me how you should be designing a new 4.0 WF in you have a workflow that spans network as well as having interprocess activities.  In 3.5 it appears you need WCF if you are handing off as async activities. But in 4.0 it appears you should be pass interprocess work through queues.  Where would I find a good example of creating a workflow of this nature starting new in 4.0? 

Access Denied creating a web application in SP Foundation 2010 installed on windows 7 with local acc



I've installed SharePoint foundation over windows 7 with a local account using this guide: http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=112

When I try to create a new web application the ribbon button is disabled. Using the link located in /_admin/createsite.aspx I get an "Access Denied" error message.

I access the SP Administration with the same user used during installation. This user is local admin and member of SQL server roles "securityadmin" and "dbcreator".

Any idea about this error?


Thanks in advance

What are the required Security permissions to call SAM accountmanagement over the wire, using System



I need to perform remote management on the local SAM database.  I am getting a security permission error, but can't figure out what the required permissions need to be.  My test harness works great as a locally authenticated user however the permission issue gets thrown when I am trying to connect to a remote host that isn't part of the domain.

The exception is getting thrown on the call to ValidateCredentials, which is found in the constructor for the LocalAccount class below, specifically you will see it  public LocalAccount(string Server, string User, string Password)

My test environment includes windows 7 machines that are working in a offline mode trying to connect to machines running XP, 2003 and Windows 7 that are not part of the domain.

Any and all help would be appreciated.


using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

namespace WindowsManagement
  class Program
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend