jamesbreen
asked on
ADSI Active Directory - User Modification VB Errors - PutEx, GetInfoEx
I sincerely need some help with this one... I've been banging my head on the wall for ages...
I'm trying to modify the telephone numbers of a bunch of users in Active Directory whose Usernames I know... It connects to the user no problem... I can then access properties like "Full Name" without a problem...
BUT
When I try to access "TelephoneNumber" I receive "The Active Directory property cannot be found in the cache". So I did some research and you need to call getInfoEx to populate the variables... which I am now doing, but still get the same error.
Anyway, that aside, as I dont necessarily need to access the variable just set it... so I tried just using Put and PutEx to set the number and I receive "Automation Error" when calling both Put and PutEx.
I would really, really appreciate some help.
Here's the code which References the Active DS Type Library - c:\winnt\system32\activeds .tlb:
'------------------------- ---------- ---
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Dim dso As IADsOpenDSObject
Dim container As IADsContainer
Dim tmpUser As IADsUser
Set dso = GetObject("WinNT:")
Set tmpUser = dso.OpenDSObject("WinNT:// AD/jamesb" , "Administrator", "password", 1)
tmpUser.GetInfoEx Array("telephonenumber"), 0
MsgBox tmpUser.Get("telephonenumb er")
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", "0123456789"
tmpUser.SetInfo
'------------------------- ---------- ---
I'm trying to modify the telephone numbers of a bunch of users in Active Directory whose Usernames I know... It connects to the user no problem... I can then access properties like "Full Name" without a problem...
BUT
When I try to access "TelephoneNumber" I receive "The Active Directory property cannot be found in the cache". So I did some research and you need to call getInfoEx to populate the variables... which I am now doing, but still get the same error.
Anyway, that aside, as I dont necessarily need to access the variable just set it... so I tried just using Put and PutEx to set the number and I receive "Automation Error" when calling both Put and PutEx.
I would really, really appreciate some help.
Here's the code which References the Active DS Type Library - c:\winnt\system32\activeds
'-------------------------
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Dim dso As IADsOpenDSObject
Dim container As IADsContainer
Dim tmpUser As IADsUser
Set dso = GetObject("WinNT:")
Set tmpUser = dso.OpenDSObject("WinNT://
tmpUser.GetInfoEx Array("telephonenumber"), 0
MsgBox tmpUser.Get("telephonenumb
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", "0123456789"
tmpUser.SetInfo
'-------------------------
ASKER
cheers mladenovicz, but this is what I have been going from!
According to the articles on that site my code should work.
According to the articles on that site my code should work.
I am not quite sure, but maybe property name is case sensitive
tmpUser.GetInfoEx Array("telephonenumber"), 0
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", "0123456789"
so try to change this to
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephonenumber", "0123456789"
tmpUser.GetInfoEx Array("telephonenumber"), 0
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", "0123456789"
so try to change this to
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephonenumber", "0123456789"
ASKER
unfortunately not... just tried it.
sorry
sorry
Try
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", Array("0123456789")
tmpUser.PutEx ADS_PROPERTY_UPDATE, "telephoneNumber", Array("0123456789")
or maybe, you should append that property to the collection:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iads_putex.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iads_putex.asp
ASKER
afraid not... the array change didnt work...
and the value I am updating is a single value... you only append when its a multivalue field I think.
and the value I am updating is a single value... you only append when its a multivalue field I think.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.winnetmag.com/Articles/ArticleID/15734/pg/2/2.html