Jump to content

Recommended Posts

Posted

Hi All,

 

First let me tell you my scenario. I am a technician at a secondary school. We have a medium sized network with AD, running server 2003 and XP clients.

 

I am trying to create a very simple VB6 executable that will reset a students password and force a password change at next logon. I'm no expert at VB but I can work my way around a program.

 

I have designed the very simple form: see attached

 

Here is the code:

 

Private Sub cmdExit_Click()
   End
End Sub

Private Sub cmdSubmit_Click()

   Dim objOU As Object, objUser As Object, objRootDSE As Object
   Dim strContainer As String, strDNSDomain As String, strPassword As String
   Dim intPwdValue As Integer
   
   'Bind to Active Directory Domain
   Set objRootDSE = GetObject("LDAP://RootDSE")
   strDNSDomain = objRootDSE.get("DefaultNamingContext")

   strContainer = "OU=Domain Users, "
   strPassword = "P@ssw0rd"
   strContainer = strContainer & strDNSDomain

   'Here we force a change of password at next logon
   intPwdValue = 0

   Set objOU = GetObject("LDAP://cn=" & txtStuNum.Text & ", " & strContainer)
   objUser.SetPassword strPassword
   objUser.Put "PwdLastSet", intPwdValue
   objUser.SetInfo

  
End Sub

 

When I run it, I enter the student's number in the text box and click submit, then and error is thrown at me.

 

"Run-time error '2147016656 (80072030)': There is no such object on the server"

 

When I debug, the "Set objOU = GetObject("LDAP://cn=" & txtStuNum.Text & ", " & strContainer)" line is highlighted in yellow.

 

Any help to get this working would be greatly appreciated.

 

Cheers for looking,

 

Chris.

Form.JPG

Posted

Something doesn't look quite right with this bit " & txtStuNum.Text & ", " & strContainer)" the things enclosed in quotes would be passed as literal text and not the values which they are set to wouldn't they?

 

Ben

Posted

No, look at the actual code, which is correct. You're quoting a quote, the whole of which is wrapped in quote marks - you know, like English should be.

 

@TriggerHappyUK: build your distinguished name string in a variable first and dump it out just before the call to GetObject, so you can see exactly what it says.

Posted

Hmm yes ok I see now that it does appear to be correct.

 

2 ways to check do as has been suggested and dump out what the string builds to or hardcode a value to be correct and run it like that and then see what it does.

 

Ben

Posted
or hardcode a value to be correct and run it like that and then see what it does.

 

If a hard value succeeds, it still doesn't help you to pin down the error... you need to know what the string looks like after you've concatenated the parts, not whether your library calls can be trusted (which you have to assume is the case, otherwise libraries would be useless).

Posted

@TriggerHappyUK: build your distinguished name string in a variable first and dump it out just before the call to GetObject, so you can see exactly what it says.

 

Thanks for the comments... Could you be a bit clearer please. :o It's been a while since I have done any programming.

 

Chris.

Posted
Thanks for the comments... Could you be a bit clearer please. :o It's been a while since I have done any programming.

 

Something like:

 

Dim strDN As String
strDN = ""LDAP://cn=" & txtStuNum.Text & ", " & strContainer
Debug.Print strDN
Set objOU = GetObject(strDN)

Posted

Here is where I am now:

 

Private Sub cmdExit_Click()
   End
End Sub

Private Sub cmdSubmit_Click()

   Dim objOU As Object, objUser As Object, objRootDSE As Object
   Dim strContainer As String, strDNSDomain As String, strPassword As String
   Dim strDN As String
   Dim intPwdValue As Integer
   
   'Bind to Active Directory Domain
   Set objRootDSE = GetObject("LDAP://RootDSE")
   strDNSDomain = objRootDSE.get("DefaultNamingContext")

   strContainer = "OU=Domain Users,"
   strPassword = "P@ssw0rd"
   strContainer = strContainer & strDNSDomain

   'Here we force a change of password at next logon
   intPwdValue = 0


   strDN = ("LDAP://cn=" & txtStuNum.Text & "," & strContainer)
   Debug.Print strDN
   Set objOU = GetObject(strDN)

   'Set objOU = GetObject("LDAP://cn=" & txtStuNum.Text & "," & strContainer)
   objUser.SetPassword strPassword
   objUser.Put "PwdLastSet", intPwdValue
   objUser.SetInfo

End Sub

 

When I run it, I get the same error:

 

"Run-time error '2147016656 (80072030)': There is no such object on the server"

 

When I debug, the "Set objOU = GetObject(strDN)" line is highlighted in yellow.

 

This may help, the value of strDN is:

 

LDAP://cn=0007,OU=Domain Users,DC=arnewood,DC=net

 

But the value of objOU has a value of:

 

Nothing

Posted
Just added a message box to test the value of strDN inplace of the debug.print. It outputted the same value as above before crashing with the same error.

 

Those two will return the same as they're both just displaying the value of strDN.

 

Might be a daft question, but you are sure that there is a student 0007 on the domain?

Posted
Those two will return the same as they're both just displaying the value of strDN.

 

Might be a daft question, but you are sure that there is a student 0007 on the domain?

 

Yeah, that's out test student account.

Posted (edited)

Shouldn't:

Set objOU = GetObject("LDAP://cn=" & txtStuNum.Text & "," & strContainer)

 

 

be

 

Set objUser = GetObject("LDAP://cn=" & txtStuNum.Text & "," & strContainer)

 

 

as you don't seem to be assigning a value to objUser before attempting to change the password?

 

If you still get a "no such object on server" error, I'd suggest grabbing an LDAP browser and checking the path to your test object.

 

Chad

Edited by Chad

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...