in reply to Re: Setting Attribute Values with ADSI
in thread Setting Attribute Values with ADSI

Thanks for answering. As I mentioned in the original post, I did the error checking after every ADSI call and got a 0 return code, I figured my sample code might be clearer if I omitted it.

I don't know for sure about having to do another GetObject. It's possible that it works that way, but I've never read anything about having to do that, and I've read the chapter that you recommended (several times), at least 20 nodes here at perlmonks about ADSI, and perhaps 50 other web pages about ADSI programming. Most of those pages use VB in their examples, but I think for the most part, the ADSI stuff has a one-to-one translation between VB and Perl. I did see a VB example on MSDN that suggests that you don't have to do that. The page at: http://technet.microsoft.com/en-us/library/ee156502.aspx shows writing an attribute, doing a SetInfo, then reading the attribute back in without doing another GetObject. I've snipped out most of the code just to keep this short and readable.

Set objUser = _ GetObject("LDAP://cn=MyerKen,ou=HR,dc=NA,dc=fabrikam,dc=com") '<snip> objUser.Put "givenName", "Ken" '<snip> objUser.SetInfo '<snip> strGivenName = objUser.Get("givenName") '<snip> Wscript.Echo "givenName: " & strGivenName

I figured all along that doing GetObject again would work (and I verified that this evening). I wanted to try to avoid that if possible, as I had designed the program around creating the connection once, and keeping it open for the duration of the program, then letting it close at the end.

I want to fully credit you with your suggestion about GetObject, because even though I believed it would work, until you suggested it I never considered it as a workaround. I was planning on opening the connection at the beginning of the program and closing it at the end. Without boring you with the details, what I can do is actually create one connection that I keep open like I was planning to do, and since I only have one object that I need to read, write, then read from, I will use a second connection for that and open it and close it as I need to do the reads and writes.