- Setting user passwords in ADAM from VB.NET with System.DirectoryServices
- Posted by Kyle Spiller on December 13th, 2003
I know I have seen many similar posts, but nothing exact.
Scenario:
ADAM retail sitting on Win 2003 Std.
Running the code directly on the server logged in as local administrator.
No domain. nonsecure setup.
dsHeuristics set to 000000001001 as per other posts.
The code below (VB.NET with framework 1.1.4322) fails with exception
x80005008 when setting the port number. This code worked when written with
VS Studio 2002 under .Net Framework 1.0
Seems that either the update to the framework or one of the security patches
(the box is up to date as of today, 12/13/03 per WindowsUpdate) has broken
something. Any ideas, anyone?
Imports System.DirectoryServices
Module Module1
Sub Main()
Const ADS_OPTION_PASSWORD_PORTNUMBER = 6
Const ADS_OPTION_PASSWORD_METHOD = 7
Const ADS_PASSWORD_ENCODE_CLEAR = 1
Dim de As DirectoryEntry = New
DirectoryEntry("LDAP://vm2003std:389/OU=LifelineUsers,O=Plmembership")
de.AuthenticationType = AuthenticationTypes.Signing Or
AuthenticationTypes.Sealing Or AuthenticationTypes.Secure
de.Username = "*******"
de.Password = "*******"
Dim newuser As DirectoryEntry = de.Children.Add("cn=TestUser1", "user")
newuser.CommitChanges()
' Set password for user.
Try
newuser.RefreshCache()
newuser.NativeObject.SetOption(ADS_OPTION_PASSWORD _PORTNUMBER, 389) '
<<<<<----- EXCEPTION THROWN HERE.
newuser.NativeObject.SetOption(ADS_OPTION_PASSWORD _METHOD,
ADS_PASSWORD_ENCODE_CLEAR)
newuser.NativeObject.SetPassword("ADAMComplexPassw ord1234")
Catch e As Exception
de.Children.Remove(newuser)
End Try
End Sub
End Module
- Posted by Dmitri Gavrilov [MSFT] on December 16th, 2003
Hmm... This seems strange since we generally see this issue on Win 2000 or
XP where it indicates that a hot fix is missing. However on Win2003 the ADSI
dlls should support this. Can you check the version of adsldp.dll and
adsldpc.dll just to make sure we have the 2003 rtm versions.
Also, do you get the same error if trying to do the same thing using ADSI
directly (rather than using System.DirectoryServices) through VBScript?
--
Dmitri Gavrilov
SDE, Active Directory Core
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Kyle Spiller" <kjspiller@tsacmoc.net> wrote in message
news:uoYNgLcwDHA.3216@TK2MSFTNGP11.phx.gbl...
- Posted by Kyle Spiller on December 17th, 2003
Dmitri, you have been a great source of information on ADAM related topics
for me since way back in beta times.
After beating on it over the weekend and having no newsgroup access at work,
I found the problem. I realized that my post was not quite accurate. The
line
newuser.NativeObject.SetOption(ADS_OPTION_PASSWORD _PORTNUMBER, 389)
was actually
newuser.NativeObject.SetOption(ADS_OPTION_PASSWORD _PORTNUMBER, ADAM_PORT)
where ADAM_PORT was defined as an integer. When I changed the code to
newuser.NativeObject.SetOption(ADS_OPTION_PASSWORD _PORTNUMBER,
CShort(ADAM_PORT) ),
everything worked again as expected. It was walking through a VBScript
version of the code that I found the problem. I will check out the versions
of the two dlls to ensure that updates went well.
Didn't have to do that before. Seems like some downcasting functionality was
lost at some point.
Again, thanks...
"Dmitri Gavrilov [MSFT]" <dmitrig@online.microsoft.com> wrote in message
news:eobG7DAxDHA.2508@TK2MSFTNGP12.phx.gbl...
- Posted by Kelvin Tsang on January 12th, 2004
Hi Dmitri,
I bumped into a problem which is similar to this problem. I have run
the code in:
http://msdn.microsoft.com/library/de...r_password.asp
But I keep getting an exception saying:
Exception has been thrown by the target of an invocation.
Exception from HRESULT: 0x80005008.
System.Runtime.InteropServices.COMException (0x80005008): Exception
from HRESULT: 0x80005008.
You have suggested that this problem usually happens on WinXP if the
OS is missing a hotfix. I am running C# code on Windows XP
Professional Version 2002 SP 1. How do I check whether the hotfix is
missing?
Thank you very much.
Warm Regards.
--
Kelvin Tsang
"Dmitri Gavrilov [MSFT]" <dmitrig@online.microsoft.com> wrote in message news:<eobG7DAxDHA.2508@TK2MSFTNGP12.phx.gbl>...
- Posted by Dmitri Gavrilov [MSFT] on January 13th, 2004
The hotfix should be Q817583 <http://support.microsoft.com/?id=817583>. As a
reference, I believe it is in the release notes for ADAM.
If you need to know if it is installed, you can look for it in Add/Remove
Programs or check for the presence of :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\HotFix\Q817583
It is slated for inclusion in XP SP2, however, it appears for now that you
need to contact PSS to get it. It should be a free call.
--
Dmitri Gavrilov
SDE, Active Directory Core
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Kelvin Tsang" <kelvin.tsang@sunaptic.com> wrote in message
news:5092bef0.0401121345.466ae0b7@posting.google.c om...
- Posted by Kelvin Tsang on January 15th, 2004
Hi Dmitri,
Right, it works right away after I obtained the Hotfix from Microsoft.
Thank you for your quick help!
-Kelvin
"Dmitri Gavrilov [MSFT]" <dmitrig@online.microsoft.com> wrote in message news:<#aaqxcf2DHA.2620@TK2MSFTNGP09.phx.gbl>...