TriggerHappyUK Posted July 7, 2010 Posted July 7, 2010 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.
plexer Posted July 7, 2010 Posted July 7, 2010 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
powdarrmonkey Posted July 7, 2010 Posted July 7, 2010 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.
plexer Posted July 7, 2010 Posted July 7, 2010 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
powdarrmonkey Posted July 7, 2010 Posted July 7, 2010 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).
TriggerHappyUK Posted July 8, 2010 Author Posted July 8, 2010 @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. It's been a while since I have done any programming. Chris.
powdarrmonkey Posted July 8, 2010 Posted July 8, 2010 Thanks for the comments... Could you be a bit clearer please. 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)
TriggerHappyUK Posted July 8, 2010 Author Posted July 8, 2010 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
TriggerHappyUK Posted July 8, 2010 Author Posted July 8, 2010 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.
LosOjos Posted July 8, 2010 Posted July 8, 2010 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?
TriggerHappyUK Posted July 8, 2010 Author Posted July 8, 2010 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.
TriggerHappyUK Posted July 8, 2010 Author Posted July 8, 2010 This little .exe(Password Reset tool for staff) works a treat and is so nearly what I am hoping to achieve. It changes the password fine but I would like to force a password change at next logon.
Chad Posted July 9, 2010 Posted July 9, 2010 (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 July 9, 2010 by Chad
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now