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):
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.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
Thanks,
Jim P.




Reply With Quote