Creating exchange mailbox

roland

New member
Joined
Oct 14, 2007
Messages
1
Programming Experience
Beginner
Hello,

I have created a program that is creating a user into Active Directory, this works fine. The only problem i have now is that i also want to create a exchange mailbox for the same at the same time the user is created.

Is there anyone that can help me creating the exchange mailbox?

I already found some info about creating a exchange user, but this needs to call CDOEXM, and i have no idea how to do this correctly so that the program is working for exchange 2000 and exchange 2003.

Thanks in advance,
Roland

This is the code i got so far:

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim strAccountName = AccountName
            Dim strPrincipalName = AccountName.Text &   My.Settings.UserLogonDomain
            Dim strFirstName = FirstName
            Dim strLastName = LastName
            Dim ADRoot As System.DirectoryServices.DirectoryEntry
            Dim rootDSE As New DirectoryEntry("LDAP://" & My.Settings.ADDomainName & "/RootDSE")
            Dim dnc As String = DirectCast(rootDSE.Properties("defaultNamingContext").Value, System.String)
            Dim usersPath As String = String.Format("LDAP://" & My.Settings.ADDomainName & "/" & My.Settings.UserContainer & ",{0}", dnc)
            ADRoot = New System.DirectoryServices.DirectoryEntry(usersPath)
            Dim oNewUser As System.DirectoryServices.DirectoryEntry
            oNewUser = ADRoot.Children.Add("cn=" & strAccountName.Text, "user")
            oNewUser.Properties("sAMAccountName").Value = strAccountName.Text
            oNewUser.Properties("userPrincipalName").Value = strPrincipalName
            oNewUser.Properties("givenName").Value = strFirstName.Text
            oNewUser.Properties("SN").Value = strLastName.Text
            oNewUser.CommitChanges()
            Dim exp As Integer = CInt(oNewUser.Properties("userAccountControl").Value)
            oNewUser.Properties("userAccountControl").Value = exp Or &H1
            oNewUser.CommitChanges()
            Dim val As Integer = CInt(oNewUser.Properties("userAccountControl").Value)
            oNewUser.Properties("userAccountControl").Value = val And Not &H2
            oNewUser.CommitChanges()
            Dim Name = AccountName.Text
            Me.AccountName.Text = String.Empty
            Me.FirstName.Text = String.Empty
            Me.LastName.Text = String.Empty
            MsgBox("User account created successfully.", _
            MsgBoxStyle.OkOnly, "Account Created")
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, _
            MsgBoxStyle.Critical, "Account not Created")
        End Try

    End Sub
 
Last edited by a moderator:

Latest posts

Back
Top