directoryservices

Get user's Exchange server and email address in .NET

送分小仙女□ 提交于 2019-12-30 07:05:09
问题 H​i. I would like to know the address of my user's Exchange server (assuming she's in a typical Windows office network). This is in a C# application. I already have the user's email address, I found it at System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress , after referencing System.DirectoryServices.AccountManagement 回答1: I use this for my Exchange client application. Install Exchange Web Services Managed API Change your C# project's Properties/Application changed

How can I get a list of Organizational Units from Active Directory?

大憨熊 提交于 2019-12-30 04:02:46
问题 I've looked into the DirectoryServices class and it seems to be what I need, but I can't seem to find the classes/methods needed to fetch a collection of Organizational Units. Can you guys give some suggestions? 回答1: You need to use an appropriate DirectorySearcher from System.DirectoryServices , and you need to search for the organizationalUnit AD class (I would recommend searching based on the objectCategory which is single-valued and indexed - much faster than using objectClass ) -

How to get all the AD groups for a particular user?

老子叫甜甜 提交于 2019-12-27 17:01:50
问题 I checked this post already. But it doesn't answer my question. I want to get all the active directory groups in which a particular user is a member. I've written the following code. But I'm not able to proceed further as I don't know how to give the filter and how to access the properties. class Program { static void Main(string[] args) { DirectoryEntry de = new DirectoryEntry("LDAP://mydomain.com"); DirectorySearcher searcher = new DirectorySearcher(de); searcher.Filter = "(&(ObjectClass

How to programmatically change Active Directory password

两盒软妹~` 提交于 2019-12-27 13:37:07
问题 I have a set of test accounts that are going to be created but the accounts will be setup to require password change on the first login. I want to write a program in C# to go through the test accounts and change the passwords. 回答1: You can use the UserPrincipal class' SetPassword method, provided you have enough privileges, once you've found the correct UserPrincipal object. Use FindByIdentity to look up the principal object in question. using (var context = new PrincipalContext( ContextType

how to list out users from pc either he created in winnt folder(local users and groups) or active directory( under domain) using c#.net

▼魔方 西西 提交于 2019-12-25 03:55:26
问题 I have implemented a c# windows application. For that application I want to provide login from windows user credentails. Now the issue is I need to get the users list from windows pc through code. How to get users list eaither user created in winnt folder (under local users and groups), or user created in active directory domain. I have an idea for get users list from winnt folder that is DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName); // DirectoryEntry

Query filter ArgumentException when trying to extending OU principal

巧了我就是萌 提交于 2019-12-24 10:38:47
问题 I am try to create extension of principal for organizationalUnit using this code below [DirectoryRdnPrefix("OU")] [DirectoryObjectClass("organizationalUnit")] public class OrganizationalUnitPrincipal : Principal { public OrganizationalUnitPrincipal(PrincipalContext Context_p) { PropertyInfo contextRaw = this.GetType().BaseType.GetProperty("ContextRaw", BindingFlags.Instance | BindingFlags.NonPublic); contextRaw.SetValue(this, Context_p, null); } } But it throws the following error: System

Crashing with C# and Directory Services on XP

断了今生、忘了曾经 提交于 2019-12-24 10:35:26
问题 I'm trying to do some simple data retrieval with C# and Directory Services, but for some reason it doesn't work on any XP machines. If I run my code on a Server 2003 machine, there are no problems. I've spent a fair bit of time trying to find out if maybe there's some redistributable I need on XP or if the functionality simply isn't there, but I've found references to other developers who have similar code working under XP. If anyone has any experience or advice to share, I'd appreciate it. A

Is it possible to get Group Notes from Active Directory?

二次信任 提交于 2019-12-24 08:48:17
问题 Active Directory groups have a 'Notes' property available through the interface (see image below) Is it possible to retrieve this information in C#? I can't seem to find the property that holds it. I've tried using the System.DirectoryServices.DirectoryEntry and System.DirectoryServices.AccountManagement.GroupPrincipal objects but none of them seem to have it. 回答1: There is a property called info which holds the information shown within this field. But it will only be added to the AD object

Impersonate not working for DirectoryServices

て烟熏妆下的殇ゞ 提交于 2019-12-24 08:34:28
问题 I'm trying to execute the following code using System.DirectoryServices; public bool HasVirtualDirectory(string serverName, string virtualDirectoryName) { try { DirectoryEntry directoryEntry = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/Root"); return directoryEntry.Children.Find(virtualDirectoryName, directoryEntry.SchemaClassName.ToString()) != null; } catch (Exception) { return false; } } As I need adminstrator rights on the server to execute this code, I used this class to

Retrieve AD Custom Attribute in One Batch

眉间皱痕 提交于 2019-12-24 03:05:38
问题 Is it possible to use the System.DirectoryServices.AccountManagement library and the PrincipalSearcher class to retrieve a custom attribute for all Principals returned from the call to FindAll() ? I'm currently using this example: http://msdn.microsoft.com/en-us/library/bb552835%28v=vs.90%29.aspx. However, when accessing my custom property/attribute, it seems to be making an additional trip to the AD store. I would like it to eagerly load this property at the initial call to FindAll() . 回答1: