Results 1 to 11 of 11

Thread: [2005] Create Exchange 2003 Mailbox

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Cleveland, Ohio
    Posts
    185

    Exclamation [2005] Create Exchange 2003 Mailbox

    Hello All,

    I am trying to write a function that will create an Exchange 2003 mailbox. I got this chunk of code off of the MSDN, but I can't get it to work. I keep getting a conversion error (see comments below):

    Code:
      CreateUserAndMailbox(ByVal UserName As String, ByVal UserFullName As String, ByVal UserTempPassword As String, ByVal strAuthUser As String, ByVal strPassword As String) As Boolean
            'TODO: Change these items to values for your domain or organization.
            Dim defaultNC As String = "DC=avtron,DC=corp"
            Dim [alias] As String = UserName
            Dim fullName As String = UserFullName
            Dim password As String = UserTempPassword
            Dim domainName As String = "avtron.corp"
            Dim homeMDB As String = "CN=Exchange1,CN=First Storage Group,CN=InformationStore,CN=ExchangeServer1,CN=Servers,CN=HomeTown,CN=Administrative Groups,CN=Avtron,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=avtron,DC=corp"
    
            Dim container As DirectoryEntry, user As DirectoryEntry
            Dim mailbox As CDOEXM.IMailboxStore
    
            '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 = 512
            'ADS_UF_NORMAL_ACCOUNT
            user.CommitChanges()
    
            'Obtain the IMailboxStore interface, create the mailbox, and commit the changes.
            '******  Conversion Error happens here *******
            mailbox = CType(user.NativeObject, IMailboxStore)
            mailbox.CreateMailbox(homeMDB)
            user.CommitChanges()
    
            Return True
        End Function
    I have the Exchange Management tools installed on my dev machine and still can't get it to work. Any help would be greatly appreciated.

    Thanks,

    Jim P.
    Last edited by jpiller; Aug 1st, 2007 at 11:51 AM.
    "The Force will be with you, always."

    --Ben Kenobi--

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width