Update active directory user from Windows Service

Hi, I have a windows service that will pull data from an external
source and I need to update this informaiton in AD from a Windows
Service.

What is the easiest way to do this? I looked at using the
ActiveDirectoryMembershipProvider but it seems that this is for
ASP.NET applications only(?) or perhaps I am missing some better
results in google.

I know that I can connect via LDAP and change details using code like
the following

  DirectorySearcher search = new DirectorySearcher();
            search.Filter = String.Format("(SAMAccountName={0})",
userName);
            search.PropertiesToLoad.Add("cn");
            SearchResult result = search.FindOne();

but I was wondering if there was a better way?

Thanks for any help
Adam
0
Adam
1/5/2010 11:41:37 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

2 Replies
929 Views

Similar Articles

[PageSpeed] 34

You also have the 
http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx 
namespace with is new in 3.5...

--
Patrice

"Adam" <admlangford@gmail.com> a �crit dans le message de 
news:86bad4a2-755e-4470-b54d-c0350f285396@b2g2000yqi.googlegroups.com...
> Hi, I have a windows service that will pull data from an external
> source and I need to update this informaiton in AD from a Windows
> Service.
>
> What is the easiest way to do this? I looked at using the
> ActiveDirectoryMembershipProvider but it seems that this is for
> ASP.NET applications only(?) or perhaps I am missing some better
> results in google.
>
> I know that I can connect via LDAP and change details using code like
> the following
>
>  DirectorySearcher search = new DirectorySearcher();
>            search.Filter = String.Format("(SAMAccountName={0})",
> userName);
>            search.PropertiesToLoad.Add("cn");
>            SearchResult result = search.FindOne();
>
> but I was wondering if there was a better way?
>
> Thanks for any help
> Adam 

0
Patrice
1/6/2010 10:31:34 AM
Use LINQ2AD (Linq to active directory, this is about as easy as it gets and 
you won't have to do all this tedious, error prone formatting.

-- 
Vapordan
Shameless Author Plug
ASP.NET 4 by Example only $20
OWC Blackbook www.lulu.com/owc

"Patrice" <http://scribe-en.blogspot.com/> wrote in message 
news:ec1yrtrjKHA.5604@TK2MSFTNGP04.phx.gbl...
> You also have the 
> http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx 
> namespace with is new in 3.5...
>
> --
> Patrice
>
> "Adam" <admlangford@gmail.com> a �crit dans le message de 
> news:86bad4a2-755e-4470-b54d-c0350f285396@b2g2000yqi.googlegroups.com...
>> Hi, I have a windows service that will pull data from an external
>> source and I need to update this informaiton in AD from a Windows
>> Service.
>>
>> What is the easiest way to do this? I looked at using the
>> ActiveDirectoryMembershipProvider but it seems that this is for
>> ASP.NET applications only(?) or perhaps I am missing some better
>> results in google.
>>
>> I know that I can connect via LDAP and change details using code like
>> the following
>>
>>  DirectorySearcher search = new DirectorySearcher();
>>            search.Filter = String.Format("(SAMAccountName={0})",
>> userName);
>>            search.PropertiesToLoad.Add("cn");
>>            SearchResult result = search.FindOne();
>>
>> but I was wondering if there was a better way?
>>
>> Thanks for any help
>> Adam
> 
0
Alvin
1/7/2010 1:36:22 AM
Reply:

Similar Artilces:

windows update 04-15-10
I am running windows vista on a MAC computer with VMWare Fusion. I cannot get the service pack 1 or internet explorer 8 update to run. i get error code 490 and 800704090 Too late now! Support for Vista Gold (no Service Packs) ended on Tuesday, 13 April 2010! Computers running Vista Gold "will no longer receive software updates from Windows Update" until SP1 has been manually installed (which will require several Prerequisite Updates to be installed first). See http://windowsteamblog.com/blogs/windowsvista/archive/2010/04/13/end-of-support-for-windows-vista-with-no...

Install FrontPage 2003 on Windows 7
i tried several times to install, the program told me it has been installed, but it is not. What can I do. On Thu, 1 Apr 2010 10:48:01 -0700, monising <monising@discussions.microsoft.com> wrote: >i tried several times to install, the program told me it has been installed, >but it is not. What can I do. Please be more explicit about what you're doing, what you're seeing, and what error messages - if any - you are getting. I have FrontPage 2003 installed on Windows 7 Ultimate x64, and it's working fine. Also, are you installing from original media? A...

Junk button in windows live accidently pressed
Whenever I open up WLM i press sync automatically as a bad habbit. Because of the loading time, the junk button usually gets inserted before the sync button, pushing it out to the right after its loaded. I therefore accidently press the junk button by accident sometimes. This is a classic Microsoft HCI problem. Surely the button should be there but greyed out when you cant click it. Having buttons moving around in menus is bad in the same way popups are bad. So break your bad habit WLM will sync automatically when 1st opened peter -- If you find a posting or message...

Saving User Settings in Outlook...
Hello everyone, Does anyone know how to save the user settings for MS outlook 2003? Thanks to all who reply, Ismael The reason I would like to be able to save the user settings is so I'll be able to restore these settings should I need to in case I had to do a clean install of WinXP and office 2003 either on the same computer of on another newly bought computer. Thanks to all who reply, Ismael "Ismael" <I_Tena@hotmail.com> wrote in message news:ueqwqfaHGHA.2948@TK2MSFTNGP10.phx.gbl... > Hello everyone, > > Does anyone know how to save the user setting...

the user authentication passed to the platform is not valid 09-20-06
Anyone receive this error message in the CRM Outlook Client? "The user authentication passed to the platform is not valid." Thanks, Scott ...

Windows Live crap
About 4 days ago I noticed a site called Windows Live ID. It suggested to set up a profile and promised that with a single username and password you could log on to all Windows Live applications such as Hotmail, Windows Live Messenger, Windows Live Mail etc. etc. I thought what a good idea, not having to have 10 different usernames and passwords, so I used my old hotmail adress and username to set up a profile. But the ID said I coildn't use my hotmail for some reason, can't remember what. A few hours later I logged on to Windows Live Messenger as I have done for years, w...

Timestamp value of GINA window presentation
I am currently troubleshooting slow logon times for a client with computer infrastructure spread across the globe. Before I start invesagating I want to create a baseline for logon times. I have modified the clients logon script to record when it starts and when it ends. I am using the computers tick count to record how long the computer has been on, but realize that there is a space of time between the user authenicating to the computer (control-alt-delete) and when the logon script starts, if the customer turns his computer on and then leave for an extended period of time I ...

Is this a correct way of doing an optimistic update
Imagine two different users executing this code at the same time. I can not use the CRecordset Update Delete methods for this. // Check to see if version number has been incremented since this view read in // the client data CClientRecordSet rs(mConn); rs.m_strFilter = "ID = "; rs.m_strFilter += client->GetKey(); rs.m_strFilter +=" AND "; rs.m_strFilter += "Version = "; rs.m_strFilter += client->GetVersion(); // Assuming here, this is acting as a lock on tables referenced mConn->BeginTrans(); rs.Open(CRecordset::snapshot, NULL, CRecordset::re...

Error- Project is used by another user -Please select another proj
Please see the subject line, when im trying to open a particular project. it gives me following error. I checked the current users, there are no users. Apart from me. There are some non PA users,i tried to remove them from activity. inspite of me removing them from activity, im geting the same error. Help !!! Ramakrishnan Hello Ram, There is a stranded user in PA000001 table. You need to clear this User/Project combination. Ajay "Ram" wrote: > Please see the subject line, when im trying to open a particular project. > it gives me following error. > > I che...

User Defined Required Fields
I have set several field on sub window Sales User-Defined Fields Entry of Sales Transaction Entry as "Required". If the user remembers to click User-Defined, then they become required. But if the user never clicks on User-Defined from Sales Transaction Entry, then they can still save the new document without the required fields entered. Does anyone know what I can do to fix this asside from continual user training? Your answer is VBA. You own Modifer, so you also have VBA enabled. You'll need to write VBA code to open the window (literally, push the button) then set th...

host unreachable after recent Windows Update
Exchange 5.5 on Windows 2000 Server, fully patched and running real swell until Wednesday morning. (Tuesday evening: applied the GDI+ patch: MS04-028.) Didn't find out until later today: internal e-mail is fine, inbound Internet e-mail is fine, but nothing goes out over the IMC. Each outbound e-mail generates Event ID 3010 warning message in the App log: host unreachable. But NSLOOKUP on that very server successfully resolve those same domain names, and ping gets replies. The only other software on this server: GroupShield 5.0 all up-to-date, and VirusScan 8.0.0 patch 1 push...

Updating Related Entities Via Workflow
I'm a complete newbie to workflows, so your help is much appreciated. In general my question is, can a parent entity be updated via workflow rules when some event occurs on a related child entity, or does this need to happen via assembly or callout? Specifically... I have a situation where leads come into our system from various places. Because I cannot add leads to a queue, I use a workflow to create a phone call for each lead and add it to a queue. Now, is it possible (through workflow) that when a user accepts the phone call activity from the queue, that the parent lead own...

User Authentication Error
Hello All, I am running CRM 3.0. I have the system administrator role. When attempting to merge 2 account records I receive an error that states, "The user authentication passed to the platform is not valid." I cannot merge the records. If anyone can, please advise. thanks. Keith ...

Issue installing FRx 6.7 on Windows 2003
I am encountering an unhandled exception error when attempting the installation. The installation prompts for the language, I select English, then Next. The progress bar makes it all the way to the right of the next screen, then I get the above error. This is a brand new quad CPU Dell OS is base WIndows Server 2003 Enterprise, not SP1 Only installed software is: IIS 6.0 (FTP, WWW, MSMQ) CA ArcServe (backup software) SQL 2000 Enterprise, Analysis Services, both at SP3a WinZip Acrobat 6.0 Reader Hello, Can you give us the exact error message you're receiving (all words and numbers fro...

Activities for an Opportunity Order
Is there any way to have activities for an Order in an Opportunity rollup and appear in the Activities/History for the Opportunity? They show up for the related account, but it would be helpful to be able to see these in the related Opportunity. Thanks, -Rick M. On Apr 20, 12:10 pm, Rick M <R...@discussions.microsoft.com> wrote: > Is there any way to have activities for an Order in an Opportunity rollup and > appear in the Activities/History for the Opportunity? They show up for the > related account, but it would be helpful to be able to see these in the > related Opp...

Active Directory/Exchange problem
All, Before I joined my current employer the admin here upgraded from Exchange 5.5 to Exchange 2000(Box A) and then added another Exchange 2000 box to the organisation(Box B)and migrated the data in Box A to Box B. Box B is now the working exchange server and Box A is no longer used. The problem is that if I actually shut down Box A I can add a new user to Active Directory but I am unable to modify a users email/smtp details. All mail can still be transferred with no problems which would lead me to believe that Exchange is Ok but there is some sort of Active Directory link between the two bo...

Pay code update with Integration Manager
I am trying to do a Pay Code update for all employees using Integration Manager using the General Payroll Update. I am able to get the standard Pay Codes to update, but cannot seem to get the "Based On" Pay Codes to update. When I log into GP and view the Employee Maintenance and Go To Pay Codes, I see the standard update. However the Based On Pay Codes remain the old rates unless I select select the Pay Code and simply click Ok. Then the update automatically is brought in. How can I get these updates to take without having to visit each of the Based On Pay Codes and sele...

error message in Outlook after running windows and office updates
Hello, I am hoping someone can help me with this. When ever a few staff tries to send a new e-mail, a message "Do you want to save changes" come up and on the back of this message I see the spell checker box come up. The problem is that if you click on "no" on the error message, it comes up with another message something like "running out of memory". I just ran all the windows and office updates on all the machines in the company and so far two employees are having this problem. Is this something to do with the updates? Any suggestions? did you try ...

Outlook should keep files in the clipboard after closing a window
When you open a message (in a new window) in Outlook 2007, and copy one or more files contained in this message, and then close the window, the file is not kept in the clipboard. I have to copy the file and paste it before closing the window. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I ...

Bizarre background window behavior in Word
I am running MS Office for Mac 2008 (12.2.4) on a 2008 Intel iMac with the most recent version of Leopard OS. Since installing a recent upgrade to Mac Office 2008, I have been having a frustrating problem when I keep multiple documents open in Word. The active document will randomly be moved to the background, while one of the inactive open documents will randomly move to the foreground. Curiously, the inactive window now in the foreground actually remains inactive, and if I continue typing, the text is placed in the active window that is now hidden in the background. The only way to b...

Do money updates install when you're not admin?
I noticed when I first start using money it told me to log on as administrator so that the updates can take effect. Is this true of all money updates? When I see the message "Money update recieved" does that mean it has also been installed or do I have to log in as admin to complete the process? In microsoft.public.money, Brian H wrote: >I noticed when I first start using money it told me to log on as >administrator so that the updates can take effect. Is this true of all money >updates? When I see the message "Money update recieved" does that mean it >has a...

Continuous update unsuccessful--this is truly bogus
Any updated info on the online account updating issues in Money 2005/2006. Example. I have several credit cards listed and setup for online account access, downloaded transactions (advanced register), etc. Suddenly the account will get an error stating that "update unsuccessful" and then never updates after that. I have read where the advice was to delete the online account and reset it up. The problems I have with that are that when I do that, now all my transaction history for that account is lost and I am given only the balance. I have selected the max for account hist...

Import directory data into Excel 2003
I have over 1000 media files that I would like to extract information from and put into an Excel spreadsheet. Using Explorer, I have defined the fields I would like to see, such as title, duration, comment etc. Now, I need to import this data into Excel. So far, I've not been able to find a way to do this. Can someone offer some suggestions please? Thanks, Nigel -- www.myoldcontacts.com - Tell your friends to tell their friends www.sysadmininc.com - Consultancy, Service, Sales, Networking... www.british-expats.com - Connect with British Expats World Wide www.kxez.com/shows_britishinv...

Macros and Active X
My ctrl+c and ctrl+v shortcuts dont work unless I turn on my active forms bar to edit mode. Any guesses why -- Message posted from http://www.ExcelForum.com Because the spreadhseet is "live". You have to go into edit mode t make any changes to control toolbox items. -- Message posted from http://www.ExcelForum.com I'm not trying to edit my active x forms, The problems is that th standard ctrl+c and ctrl+v copy and paste short cuts wont work unles the active x edit mode is turned on. I don't have to turn on the active x edit mode to use these short cut in other wo...

SQL-Dynamics V10 Users
I have some messy stuff going on with Dynamics and SQL users. I have users that are users in the databases, but not in Dynamics, and users in Dynamics that are not in SQL. Is there a script or anything to run to straighten this out? Right now it is manual process where I have to go user by user, check in dynamics and which companies they use, then go to SQL and check each database... Any suggestions? -- Doug Why can't you do this through the user interface? Did you resore a backup of Dynamics of something? As far as I know, the only way to create a GP login is to do it throu...