???? ID: 313114 - ????? ???????: 04 ?????? 2010 - ??????: 2.0

????? C# ?? ????? ?? ????????-????? ???????????? ?? ????? ?? ??? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ??? ?? ??? ???? ????? ?? ?? ???? ?? ??? ?????????? ????????-????? ????? ?? ???System.DirectoryServices??? ????? ?? CDO ?? ??? Exchange ??????? (CDOEXM)?

??????????

????? ???? outlines ???????? ?????????, ??????????, ??????? ??????, ?? ???? ???? ???:
  • ?? Microsoft Windows 2000-?????? ????? Microsoft Exchange 2000 ??????? ??
  • Microsoft Visual C# 2005 ?? Microsoft Visual C# .NET
  • Microsoft Exchange 2000 ?????? ??????? ????? ?? ???????? ??? ?? ?? ??? ????? ??

???? ???????

??? ??? C# ????????? ?????

  1. ????? C# 2005 ?? Visual C# .NET ???, ????? ??? ??? C# ????? ????????? ?? MBTest ??? ???
  2. ?????? Explorer ???, ???? ????????????? ????-????? ????, ?? ???? ????????? ??????.
  3. ????? ????.NET??? ??, ????????? ?????? ??????System.DirectoryServices??? ????? ???
  4. ????? ????COM??? ??, ??? ?????? ??????Exchange ??????? ?? ??? Microsoft CDO.
  5. Class1.cs ????? ??? ??? ?? ????? ??? ?? ???????????? ?????

    ???:????? C# 2005, ??? Program.cs ????? ??? ??? ???? ????? ?? ??????
    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;
              }
         }
    }
    					
  6. ??? TODO ??? ??? ?? ?? ????????? ?????????????? ?? ?? ?? ???? ????? ?? ??? ??? ??? ??? ???
  7. ????????? ?? ?????? ????, ?? ???? ??? ????????? ??????
  8. ?? ??? ???? ?????? ????? ??? ?? ????? ??? Microsoft ??????? ????? (MMC) ??? ?????? ??????????? ?????????? ?? ???????? ?????-?? ?? ??????? ???? ?? ?????? ????? ?? ?????????? ???????? ??? ??? ?????????? ?????? ?????? ?? ?? ?????????? ????????-?????, ?? ??? ?????????? ?? ??? ????? ?? ?? ???Exchange??? ?????, ?? ?? ??? ???????? ?????? ?? ???????? ?? ?????????? ?? ???Exchange ?????????? ?? ????? ????..

??? ?? ?????

??? ??? DirectoryEntry ?????

????????? ???? ?? ?? ??? ?? (?? ?????? ???, ?????????? ????????) ??? ???????? ?? ????? ???? ?? ??? ???? ???? ?? ???? ???????? ??? ??? ?????????? ?????? ???? ??? ?? "cn =" ????????? ?? ?? ?????????? ?? ??? ?? ????
container = new DirectoryEntry("LDAP://cn=users," + defaultNC);
user = container.Children.Add("cn=" + fullName, "user");
				

??? ?????????? ?? ??? ??? ????

  1. ???? ??? ?? ??? ????? ????sAMAccountName. ?? ?? ???????? ??????? ??? ?????????? ???? ???? ????? ?? ??? ?? ??? ??? ????????? ?????
  2. ???? ???????? ????????? ???? ??? ??, ??????? ???CommitChanges?? ?????????? ?? ?????????? ??? ???????
  3. ???IADs::SetPassword??????? ??? ????? ?? ?? ??? ???? ?? ??? ???? ???? ?????CommitChanges.
  4. ?????????? ?? ??????? ???? ????? ????userAccountControl??????? ???
    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();
    				

??? ??? ??? ????? ?????

  1. ??????? ???? ?? ???IMailboxStore??????? castDirectoryEntry.NativeObject?? ??????? ?? cast ????? ??? ??? ??? ???? ??? CDOEXM ???????? ?? ??????? ???? ???
  2. ???CreateMailbox????, ?? ???? Exchange ?????? ??? ??? ???????? ?????? ?? ??? ??? ????? ???????? ????
  3. ???CommitChanges?? DirectoryEntry ?? ???????? ?? ?????? ?? ??? ???
    //Obtain the IMailboxStore interface, create the mailbox, and commit the changes.
    mailbox = (IMailboxStore)user.NativeObject;
    mailbox.CreateMailbox(homeMDB);
    user.CommitChanges();
    				

?????? ??????

  • ???? ?????????? ?? ???? ???????? ?? ????? ?? ??? ????? ??? ???? ?????? ???? ?????? ??? ??????????, Windows 2000-?????? ????? ??? ?????????? ????????-????? ?????, ?? ???? ?????? ????? ?? ??? Windows 2000 ????? ?????????? ???? ?? ????? ???
  • ?? ??? ?? ?? Exchange 2000 Server-?????? ???????? ?? ????? ???? ???? ???????? ?? ????? ??, ??? ?? Exchange 2000 ?????? ??????? ????? ?? ???????? ?? ??????? ???? ?????? ??? ??? ?? ???? ????, CDOEXM ?????? ???? ?? ?? cast ???? ?? ???IMailboxStore??????? throws ?? InvalidCastException ??????????? ???:
    'System.InvalidCastException' ?????? ?? ??? ????? unhandled MBTest.exe ??? ? ?? ??
    ???????? ???????: ????????? ???? cast ????? ???? ???
  • ??? ???? ??? ???? ?? ?? ?????? ????? ??????? ???? ??IMailboxStore.CreateMailbox, ???????? ???? ?? ?? ?? ???? ?? ??? ???? ??? ???????? ???? ?????? ??? ??? ????? ???????? ?????? ??? ??? ?? ???? ??, ?? ????? ?? ???? ?? ?????? ????? ??????? ???? ??:
    'System.Runtime.InteropServices.COMException' ?????? ?? ??? ????? unhandled MBTest.exe ??? ? ?? ??
    ???????? ???????: ????? ?? ??? ??? ???????? ???? ???

??????

?? ???? ??? ???? ??????? ?? ???System.DirectoryServices??? ????? ???, ????? Microsoft ?????? ??????? (MSDN) ?? ???? ??? ????:
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.directoryservices .aspx (http://msdn2.microsoft.com/en-us/library/system.directoryservices(vs.71).aspx)
CDOEXM ?? ???? ??? ???? ??????? ?? ??? ????? MSDN ??? ???? ?? ????:
HTTP://msdn2.Microsoft.com/en-us/library/ms876280.aspx (http://msdn2.microsoft.com/en-us/library/ms876280.aspx)

???? ???? ???? ??:
  • Microsoft Visual C# 2005
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Exchange 2000 Server Standard Edition
  • Microsoft Exchange 2000 Enterprise Server
??????: 
kbdswadsi2003swept kbhowtomaster kbmt KB313114 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:313114  (http://support.microsoft.com/kb/313114/en-us/ )