I do a search, and one of the links is to Microsoft's Technet, namely, this one:
http://technet.microsoft.com/en-us/library/cc758918%28WS.10%29.aspx
It helped me figure out how to make a VBScript, but one of the more annoying things was... The script was semi-generic and kind of assumed a few things... Things that could go HORRIBLY HORRIBLY wrong, with little explanation.
For example:
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
I get this part. Create a nice little Object and assign it to ADSysInfo, create another Object that gets User object info and set it to CurrentUser.
But here is the twist.
strGroups... It's an object. You use the function LCase, which puts everything in a STRING into lower case. What throws everything off is the Join function.
The Join function expects certain information, in this case, an Array and it takes an array of things and joins it into one string.
Little does the explanation of this page does is tell you what CurrentUser.MemberOf returns. In fact, I had to find it in other webpages. What happens is that it can kick out 3 different kinds of answers.
1) If the user is not part of any groups, just Domain Users, which is also a default, catch-all group for a user in a Domain. CurrentUser.MemberOf returns "". That's right... A null string.
2) If the user is in ONE group, other than Domain Users... It returns a STRING of that group.
3) If the user is in more than one group, other than Domain Users... It returns an ARRAY of those groups.
So... This part wasn't really well thought out, at least, not logically.
So we come up to the next interesting part that I found entertaining on how many programmers of this tackled this.
Many used a lot of methods, that I felt was a bit over the top. My solution to how to handle this three tier issue was to do the following:
If IsArray(CurrentUser.MemberOf) then
strGroups = LCase(Join(CurrentUser.MemberOf))
Else
strGroups = LCase(CurrentUser.MemberOf)
End If
It took me a bit of digging to find a function that could simplify the whole "Is it an Array or Not?" part. A lot of the other solutions seemed to want to do something more elaborate or complex when it could just be done this way. And believe me, do a search on this, you will find some that seem to want to do a lot more than just this to simply get the groups in something that is a little more usable and overly complex.
Now I will admit, I didn't exactly make my own login script any more 'simpler', but then again, every place has their own way of handling things, my job is no different with that regard as well. Also, I won't claim to be a VBscript expert... I just find it interesting that out of all the posts I saw, a lot of them focused on a very complex, overly coded way to do something that I finally figured out how to do with one simple function and broke it down to a simple if then else type setup.
Course, it could also be that the IsArray function came a little later on some of the posts, but then again, different ways to figure out problems.
No comments:
Post a Comment