Well I'm writing a program, that creats a Active Directory User and its mailbox in Exchange 2003.
In msdn I found this code:
Code:
using System;
using CDOEXM;
using System.DirectoryServices;
namespace MBTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//TODO: Change these items to values for your domain or organization.
string defaultNC = "DC=yourdomain,DC=com";
string alias = "jsmith";
string fullName = "Joseph Smith";
string password = "TestMb123.";
string domainName = "yourdomain.com";
string homeMDB = "CN=Mailbox Store (Your Server),CN=Your Storage Group,"
+ "CN=InformationStore,CN=Your Server,CN=Servers,"
+ "CN=Your Administrative Group,CN=Administrative Groups,"
+ "CN=Your Org,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=Yourdomain,DC=Com";
DirectoryEntry container, user;
CDOEXM.IMailboxStore mailbox;
//This creates the new user in the "users" container.
//Set the sAMAccountName and the password
container = new DirectoryEntry("LDAP://cn=users," + defaultNC);
user = container.Children.Add("cn=" + fullName, "user");
user.Properties["sAMAccountName"].Add(alias);
user.CommitChanges();
user.Invoke("SetPassword", new object[]{password});
//This enables the new user:
user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
user.CommitChanges();
//Obtain the IMailboxStore interface, create the mailbox, and commit the changes
mailbox = (IMailboxStore)user.NativeObject;
mailbox.CreateMailbox(homeMDB);
user.CommitChanges();
return;
}
}
}
Will this code work with Exchange 2k3 too, because it is for Exchange 2k.
The central question of my thread is something else. At the beginning of the Code, there is the Attribute homeMDB set with a certain value.
In your Book "professional c#" there is in chapter dealing with ad a sample code, where you enter server, username and password, and the program gets the defaultNamingContext of the domain.
Is there any way, that I can get the value for homeMDB in the same way, as the defaultNamingContext, so that this code works on any server?
thx
Herbert