bobby010606
asked on
Disable user exchange mailbox from AD using VB.NET
Hi Experts,
I need to disable the exchange mailbox from AD using .NET ...
For this i am getting all the users in a listbox1 ...so when selected a user from the listbox and when i click on the button i need to disable the exchange Mailbox from AD....
For this i added the referances like CDOEXM and CDO
Please find the below code .....i am getting an error like "CDOEXM.IMailRecipient is unable to cast "...
can any one help me is there any better way to do this.....i really appriciate if any one suggest me in different way to disable the Exchange Mailbox from AD
I need to disable the exchange mailbox from AD using .NET ...
For this i am getting all the users in a listbox1 ...so when selected a user from the listbox and when i click on the button i need to disable the exchange Mailbox from AD....
For this i added the referances like CDOEXM and CDO
Please find the below code .....i am getting an error like "CDOEXM.IMailRecipient is unable to cast "...
can any one help me is there any better way to do this.....i really appriciate if any one suggest me in different way to disable the Exchange Mailbox from AD
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim UserName As String
Dim objRecip As CDOEXM.IMailRecipient
UserName = "CN=" + ListBox1.SelectedItem + "," + oupath
Dim objuserpath As DirectoryEntry
objuserpath = New DirectoryEntry("LDAP://" + UserName + "")
objRecip = DirectCast(objuserpath, CDOEXM.IMailRecipient)
objRecip.MailDisable()
objuserpath.CommitChanges()
Catch ex As Exception
MessageBox.Show(ex.Message + " " + ex.StackTrace)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
soory i forget to mension i am working on exchange server 2003...will the 1st post code work on Exchange server 2003
powershellcommand will not work but the vbscript will.
bol
Hilal
bol
Hilal
ASKER
is there any other solution Hilal1924
Yes Of course there are. What exactly do you need aprt from Disabling Mailbox.
1. Do you want to disable the user account ?
2. Do you want to delete the account as well ?
3. Do you need to disable this for many users or just a few ?
Hilal
1. Do you want to disable the user account ?
2. Do you want to delete the account as well ?
3. Do you need to disable this for many users or just a few ?
Hilal
ASKER
i really appriciate about your previous post
i just need to disable Mailbox of the user account.....any .NEt script will work for me Hilal1924
i just need to disable Mailbox of the user account.....any .NEt script will work for me Hilal1924
ASKER
Hilal any luck ...plz help me
Again Sorry for the delay: By Disabling, do you mean just remove the access or delete the mailbox. Removing access would mean that they will not be able to log in via Outlook, Webmail, ActiveSync etc. While as Deleting will delete the entire Mailbox.
Hilal
Hilal
ASKER
Yaa i just want to remove the access the user should not able to log in via Outlook, Webmail, ActiveSync etc.
I found it at:
http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=2915
Hilal
Open in new window