By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

ADAM user SetOption, SetPassword having exception HRESULT: 0x80005008

P: n/a
I have problem setting the password for an ADAM user using C#. I used
the SetPassword code given in the Microsoft page, changed several
parameters, but ran into an exception. I wonder if other people have
solved this problem. But I have searched Google groups for a couple
days but still couldn't get a solution.

I copied the code from:

http://msdn.microsoft.com/library/de...r_password.asp

Then when the program reaches the first call of:

objUser.Invoke("SetOption", ...);

It throws the an exception with the following information:

Message:
Exception has been thrown by the target of an invocation.

BaseException:
Exception from HRESULT: 0x80005008.

Inner Exception:
System.Runtime.InteropServices.COMException (0x80005008):
Exception from HRESULT: 0x80005008.

Source:
mscorlib

StackTrace:
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args)
at System.DirectoryServices.DirectoryEntry.Invoke(Str ing
methodName, Object[] args)
at WindowsApplication1.Form1.button1_Click(Object sender, EventArgs
e) in c:\setpassword\windowsapplication1\form1.cs:line 153
System.Object InvokeDispMethod(System.String,
System.Reflection.BindingFlags,

TargetSite:
System.Object, System.Object[], Boolean[], Int32, System.String[])

For your information, here is the code I have:

<-- code begins -->

private void button1_Click(object sender, System.EventArgs e)
{
const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const long ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_REQUIRE_SSL = 0;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;

AuthenticationTypes AuthTypes; // Authentication flags.
int intPort; // Port for instance.
DirectoryEntry objUser; // User object.
string strPath; // Binding path.
string strPort; // Port for instance.
string strServer; // Server for instance.
string strUser; // User DN.

// Construct ADsPath binding string.
// Change "localhost" to appropriate server.
// Change "389" to LDAP port appropriate for instance,
// or use SSL port (default = "636") for secure connection.
// Change "CN=TestUser,O=Fabrikam,C=US" to DN of user.
strServer = "[MY_LDAP_SERVER]";
strPort = "389";
strUser = "[A_USER_DISTINGUISHED_NAME]";
strPath = String.Concat("LDAP://", strServer,
":", strPort, "/", strUser);
Debug.WriteLine("Bind to: " + strPath);

// Set authentication flags.
// For non-secure connection, use LDAP port and
// ADS_USE_SIGNING |
// ADS_USE_SEALING |
// ADS_SECURE_AUTHENTICATION
// For secure connection, use SSL port and
// ADS_USE_SSL | ADS_SECURE_AUTHENTICATION
AuthTypes = AuthenticationTypes.Signing |
AuthenticationTypes.Sealing |
AuthenticationTypes.Secure;

// Bind to user object using LDAP port.
try
{
objUser = new DirectoryEntry(
strPath, "[LDAP_USER_NAME]", "[LDAP_USER_PASSWORD", AuthTypes);
objUser.RefreshCache();
}
catch (Exception e)
{
Debug.WriteLine("Error: Bind failed.");
Debug.WriteLine(" " + e.Message);
return;
}

// Set port number, method, and password.
intPort = Int32.Parse(strPort);
try
{
// Note: A password should normally
// not be entered in code,
// but should be obtained from the user interface.

objUser.Invoke("SetOption", new object[]
{ADS_OPTION_PASSWORD_PORTNUMBER, intPort}); <-- **Exception thrown
here**

objUser.Invoke("SetOption", new object[]
{ADS_OPTION_PASSWORD_METHOD,
ADS_PASSWORD_ENCODE_CLEAR});

objUser.Invoke("SetPassword", new object[]
{"goodpassword"});

}
catch (Exception e)
{
Debug.WriteLine("Error: Set password failed.");
Debug.Indent();
Debug.WriteLine(e.Message);
Debug.WriteLine("base exception\n" + e.GetBaseException().Message);
Debug.WriteLine("inner exception\n" + e.InnerException);
Debug.WriteLine("source\n" + e.Source);
Debug.WriteLine("StackTrace\n" + e.StackTrace);
Debug.WriteLine("TargetSite\n" + e.TargetSite);
return;
}

Debug.WriteLine("Success: Password set.");
return;

}

<-- code ends -->

Thank you very much and I appreciate anyone who has any suggestions!
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Problem solved!
I have to phone up Microsoft to get them e-mail me a Hotfix.

cool.

le****@mail.com (Lekyan) wrote in message news:<cb*************************@posting.google.c om>...
I have problem setting the password for an ADAM user using C#. I used
the SetPassword code given in the Microsoft page, changed several
parameters, but ran into an exception. I wonder if other people have
solved this problem. But I have searched Google groups for a couple
days but still couldn't get a solution.

I copied the code from:

http://msdn.microsoft.com/library/de...r_password.asp

Then when the program reaches the first call of:

objUser.Invoke("SetOption", ...);

It throws the an exception with the following information:

Message:
Exception has been thrown by the target of an invocation.

BaseException:
Exception from HRESULT: 0x80005008.

Inner Exception:
System.Runtime.InteropServices.COMException (0x80005008):
Exception from HRESULT: 0x80005008.

Source:
mscorlib

StackTrace:
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args)
at System.DirectoryServices.DirectoryEntry.Invoke(Str ing
methodName, Object[] args)
at WindowsApplication1.Form1.button1_Click(Object sender, EventArgs
e) in c:\setpassword\windowsapplication1\form1.cs:line 153
System.Object InvokeDispMethod(System.String,
System.Reflection.BindingFlags,

TargetSite:
System.Object, System.Object[], Boolean[], Int32, System.String[])

For your information, here is the code I have:

<-- code begins -->

private void button1_Click(object sender, System.EventArgs e)
{
const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const long ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_REQUIRE_SSL = 0;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;

AuthenticationTypes AuthTypes; // Authentication flags.
int intPort; // Port for instance.
DirectoryEntry objUser; // User object.
string strPath; // Binding path.
string strPort; // Port for instance.
string strServer; // Server for instance.
string strUser; // User DN.

// Construct ADsPath binding string.
// Change "localhost" to appropriate server.
// Change "389" to LDAP port appropriate for instance,
// or use SSL port (default = "636") for secure connection.
// Change "CN=TestUser,O=Fabrikam,C=US" to DN of user.
strServer = "[MY_LDAP_SERVER]";
strPort = "389";
strUser = "[A_USER_DISTINGUISHED_NAME]";
strPath = String.Concat("LDAP://", strServer,
":", strPort, "/", strUser);
Debug.WriteLine("Bind to: " + strPath);

// Set authentication flags.
// For non-secure connection, use LDAP port and
// ADS_USE_SIGNING |
// ADS_USE_SEALING |
// ADS_SECURE_AUTHENTICATION
// For secure connection, use SSL port and
// ADS_USE_SSL | ADS_SECURE_AUTHENTICATION
AuthTypes = AuthenticationTypes.Signing |
AuthenticationTypes.Sealing |
AuthenticationTypes.Secure;

// Bind to user object using LDAP port.
try
{
objUser = new DirectoryEntry(
strPath, "[LDAP_USER_NAME]", "[LDAP_USER_PASSWORD", AuthTypes);
objUser.RefreshCache();
}
catch (Exception e)
{
Debug.WriteLine("Error: Bind failed.");
Debug.WriteLine(" " + e.Message);
return;
}

// Set port number, method, and password.
intPort = Int32.Parse(strPort);
try
{
// Note: A password should normally
// not be entered in code,
// but should be obtained from the user interface.

objUser.Invoke("SetOption", new object[]
{ADS_OPTION_PASSWORD_PORTNUMBER, intPort}); <-- **Exception thrown
here**

objUser.Invoke("SetOption", new object[]
{ADS_OPTION_PASSWORD_METHOD,
ADS_PASSWORD_ENCODE_CLEAR});

objUser.Invoke("SetPassword", new object[]
{"goodpassword"});

}
catch (Exception e)
{
Debug.WriteLine("Error: Set password failed.");
Debug.Indent();
Debug.WriteLine(e.Message);
Debug.WriteLine("base exception\n" + e.GetBaseException().Message);
Debug.WriteLine("inner exception\n" + e.InnerException);
Debug.WriteLine("source\n" + e.Source);
Debug.WriteLine("StackTrace\n" + e.StackTrace);
Debug.WriteLine("TargetSite\n" + e.TargetSite);
return;
}

Debug.WriteLine("Success: Password set.");
return;

}

<-- code ends -->

Thank you very much and I appreciate anyone who has any suggestions!

Nov 15 '05 #2

P: n/a
So what was the hotfix that microsoft sent you? I'm trying to perform the same function and am getting the same issue from my web server that is attached to the domain. I run the code locally and I don't have any issues, but when it hits the first SetOption is errors. If you have the name of the hotfix or who you talked to at Microsoft I would appreciate it.

Thanks,
m blackstone

From http://www.developmentnow.com/g/36_2...0x80005008.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Mar 3 '06 #3

P: n/a
Really great, you also post the answer....

From http://www.developmentnow.com/g/36_2...0x80005008.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Oct 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.