![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Logon script - function array and select case not working Hi all, I am trying to rewrite my logon scripts which are all in vbscript. the scripts are written in a framework model, eg: control script,hashtable script and subscripts which are for each group. the hash table, has all the names, and server paths, and all the scripts use those names from the central hash table (via an include function) (this is so if server name changes i just change the path in the hash table) this all works well, except, the function i am using for the rules in the control script causes alot of querrys to AD. as there are alot of groups. so my thinking was have a function dump all the groups into an array, pass the array to a select case and fire off the subscripts inside the case statement. (there are more the 60 groups is there a limit to case? here is what i have: /code dim dataarray() dim data dim retrv dim obj set objFSO = CreateObject("Scripting.FileSystemObject") set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) objTSout.writeline retrv retrv = checkgrp 'for each obj in retrv Select Case retrv Case "group name here" wscript.echo "ok" Case "green" document.bgColor = "green" Case "blue" document.bgColor = "blue" 'Case Else MsgBox "pick another color" End Select 'next private function checkgrp() 'dim dataarray() 'dim data On Error Resume Next Set objADSysInfo = CreateObject("ADSystemInfo") strUser = objADSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser) For Each strGroup in objUser.memberOf Set objGroup = GetObject("LDAP://" & strGroup) 'Wscript.Echo objGroup.CN redim Preserve dataarray(data) dataarray(data) = objGroup.CN retrv = dataarray(data) 'wscript.echo dataarray(data) 'objTSout.writeline dataarray(data) 'objTSout.writeline checkgrp Next 'objTSout2.writeline dataarray() objTSout2.writeline retrv objTSout4.writeline dataarray(data) 'wscript.echo strname end function wscript.echo "script has finished running" /end code |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Logon script - function array and select case not working "Nex6" <Nex6@xxxxxx> wrote in message news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: > Hi all, > > I am trying to rewrite my logon scripts which are all in vbscript. the > scripts are written in a framework model, eg: control script,hashtable > script and subscripts which are for each group. > > the hash table, has all the names, and server paths, and all the scripts > use those names from the central hash table (via an include function) > (this is so if server name changes i just change the path in the hash > table) > > > this all works well, except, the function i am using for the rules in the > control script causes alot of querrys to AD. as there are alot of groups. try to do it. Quote: > so my thinking was have a function dump all the groups into an array, the domain? Quote: > pass the array to a select case and fire off the subscripts inside the > case statement. (there are more the 60 groups is there a limit to case? Quote: > here is what i have: > > > /code > > dim dataarray() > dim data > dim retrv > dim obj > > > > set objFSO = CreateObject("Scripting.FileSystemObject") > set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) > set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) > set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) > set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) > > objTSout.writeline retrv that retrv has yet to be assigned a value? Quote: > retrv = checkgrp Quote: > 'for each obj in retrv > Select Case retrv > Case "group name here" wscript.echo "ok" > Case "green" document.bgColor = "green" > Case "blue" document.bgColor = "blue" > 'Case Else MsgBox "pick another color" > End Select either "group name here", "green", or "blue". If retrv is anything else, nothing will happen. When you run this, what happens? I expect nothing as noted in my comment just after the end function statement... Also, where is the document object defined? Quote: > 'next > > > private function checkgrp() > 'dim dataarray() > 'dim data > > > On Error Resume Next > Set objADSysInfo = CreateObject("ADSystemInfo") > strUser = objADSysInfo.UserName > Set objUser = GetObject("LDAP://" & strUser) > For Each strGroup in objUser.memberOf > Set objGroup = GetObject("LDAP://" & strGroup) > 'Wscript.Echo objGroup.CN > redim Preserve dataarray(data) Quote: > dataarray(data) = objGroup.CN > retrv = dataarray(data) idea. Quote: > > > 'wscript.echo dataarray(data) > > > 'objTSout.writeline dataarray(data) > 'objTSout.writeline checkgrp > > Next > > > > > 'objTSout2.writeline dataarray() > objTSout2.writeline retrv > objTSout4.writeline dataarray(data) > > 'wscript.echo strname > > > end function returned has nothing to do with anything the function has done. Quote: > wscript.echo "script has finished running" > > > /end code contains numerous errors, I am wondering why you think it is the function and select case statements themselves that are responsible rather than your code. /Al |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Logon script - function array and select case not working This, is really the first time I tryed to mess with arrays and select case, I do a fair amount of scripting but nothing with case and arrays. i used a dicionary object but that was it. On Tue, 9 Jun 2009, Al Dunbar wrote: Quote: > > > "Nex6" <Nex6@xxxxxx> wrote in message > news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: >> Hi all, >> >> I am trying to rewrite my logon scripts which are all in vbscript. the >> scripts are written in a framework model, eg: control script,hashtable >> script and subscripts which are for each group. >> >> the hash table, has all the names, and server paths, and all the scripts >> use those names from the central hash table (via an include function) (this >> is so if server name changes i just change the path in the hash table) >> >> >> this all works well, except, the function i am using for the rules in the >> control script causes alot of querrys to AD. as there are alot of groups. > In my experience, testing group membership is expensive, no matter how you > try to do it. > Quote: >> so my thinking was have a function dump all the groups into an array, > How have you determined that this will be faster or result in fewer trips to > the domain? if ismember "groupname" then obj.run "\\ad\sysvol\~\subscriptdept.vbs end if only alot of them... like about 50 or 60, so every querry is a call to AD. thats too much, i want/need to cut that down. Quote: > Quote: >> pass the array to a select case and fire off the subscripts inside the >> case statement. (there are more the 60 groups is there a limit to case? > I am unaware of any limit to the number of cases in a select case block... > Quote: >> here is what i have: >> >> >> /code >> >> dim dataarray() >> dim data >> dim retrv >> dim obj >> >> >> >> set objFSO = CreateObject("Scripting.FileSystemObject") >> set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) >> set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) >> set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) >> set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) >> >> objTSout.writeline retrv > what value are you expecting this statement to write into the file, given > that retrv has yet to be assigned a value? infact all the writelines are just for debugging to help me see output. Quote: > Quote: >> retrv = checkgrp > what value are you expecting this will assign to retrv? case. I have been playing with it alot, so some things may be messy ![]() Quote: > Quote: >> 'for each obj in retrv >> Select Case retrv >> Case "group name here" wscript.echo "ok" >> Case "green" document.bgColor = "green" >> Case "blue" document.bgColor = "blue" >> 'Case Else MsgBox "pick another color" >> End Select > The above will do one of three actions depending on the value of retrv being > either "group name here", "green", or "blue". If retrv is anything else, > nothing will happen. > each stage to files for me to look at. Quote: > When you run this, what happens? I expect nothing as noted in my comment just > after the end function statement... function. Quote: > > Also, where is the document object defined? > Quote: Quote: >> 'next >> >> >> private function checkgrp() >> 'dim dataarray() >> 'dim data >> >> >> On Error Resume Next >> Set objADSysInfo = CreateObject("ADSystemInfo") >> strUser = objADSysInfo.UserName >> Set objUser = GetObject("LDAP://" & strUser) >> For Each strGroup in objUser.memberOf >> Set objGroup = GetObject("LDAP://" & strGroup) >> 'Wscript.Echo objGroup.CN >> redim Preserve dataarray(data) > where does "data" get its value from? > member ship and everyone will be different. Quote: Quote: >> dataarray(data) = objGroup.CN >> retrv = dataarray(data) > Assigning a value from within a function to a global variable is not a good > idea. commented out at the top of the function. Quote: > Quote: >> >> >> 'wscript.echo dataarray(data) >> >> >> 'objTSout.writeline dataarray(data) >> 'objTSout.writeline checkgrp >> >> Next >> >> >> >> >> 'objTSout2.writeline dataarray() >> objTSout2.writeline retrv >> objTSout4.writeline dataarray(data) >> >> 'wscript.echo strname >> >> >> end function > Since no value has been assigned to the name of the function, the value > returned has nothing to do with anything the function has done. > work. so i , after google and nothing, basicly am trying everything I can think of. but since i never really played with arrays that much, and passing data from an array in a function seems to be a black art in vbscript.... Quote: Quote: >> wscript.echo "script has finished running" >> >> >> /end code > Neither the intent nor the execution of the code is clear to me. Since it > contains numerous errors, I am wondering why you think it is the function and > select case statements themselves that are responsible rather than your code. > object, in the function get the array populted with the user who runs it, with all the groups. then, the select case, would be formated like so: select case case script_department.vbs end case only like 60 cases. then those subscript, are the real login scripts for the users. and, those subscripts, i have an inlcude function the pulls a hashtable with everything they need to map all the drivers etc. hope this clears it up some. Quote: > /Al > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Logon script - function array and select case not working I like to use Dictionary Objects when I must bind to many objects, and I want to avoid binding to the same object repeatedly. However, I don't see where that can happen when you are dealing with only one user. In the snippet I posted earlier, I bind to every group the user is a direct member of (except the "Primary" group, Domain Users). The Groups method of the user object returns a collection of object references, one for each group, so a lot of binding happens. If you are going to test membership in just a few groups, it would be more efficient to instead bind to the group objects and use the IsMember method of the group object. I'm not sure what you really want to do, but if this helps, the code would be similar to: ========= Option Explicit Dim objSysInfo, strUser, objUser, objGroup Set objSysInfo = CreateObject("ADSystemInfo") strUser objSysInfo.UserName) Set objUser = GetObject("LDAP://" & strUser) ' Check membership in Group A. First bind to the group object. Set objGroup = GetObject("LDAP://cn=Group A,ou=West,dc=MyDomain,dc=com") If (objGroup.IsMember(objUser.AdsPath) = True) Then ' User is a member of the group, do something. End If ' Check membership in Group B. First bind to the group object. Set objGroup = GetObject("LDAP://cn=Group B,ou=West,dc=MyDomain,dc=com") If (objGroup.IsMember(objUser.AdsPath) = True) Then ' User is a member of the group, do something. End If ====== I like to use Option Explicit and Dim all variables, as it makes troubleshooting much easier. This is especially important in logon scripts, where typos can cause havoc. If the average user is a member of 5 groups and you want to check membership in 3, the above is more efficient. However, the difference could not be measured. If you need to check membership in 10 groups, the previous snippet would make more sense, but again, I doubt it would make a measurable difference. Also, so far I see no value to using functions or subroutines. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "Nex6" <Nex6@xxxxxx> wrote in message news:alpine.WNT.2.00.0906091721360.8168@xxxxxx Quote: > This, is really the first time I tryed to mess with arrays and select > case, I do a fair amount of scripting but nothing with case and arrays. i > used a dicionary object but that was it. > > > > On Tue, 9 Jun 2009, Al Dunbar wrote: > Quote: >> >> >> "Nex6" <Nex6@xxxxxx> wrote in message >> news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: >>> Hi all, >>> >>> I am trying to rewrite my logon scripts which are all in vbscript. the >>> scripts are written in a framework model, eg: control script,hashtable >>> script and subscripts which are for each group. >>> >>> the hash table, has all the names, and server paths, and all the scripts >>> use those names from the central hash table (via an include function) >>> (this is so if server name changes i just change the path in the hash >>> table) >>> >>> >>> this all works well, except, the function i am using for the rules in >>> the control script causes alot of querrys to AD. as there are alot of >>> groups. >> In my experience, testing group membership is expensive, no matter how >> you try to do it. >> Quote: >>> so my thinking was have a function dump all the groups into an array, >> How have you determined that this will be faster or result in fewer trips >> to the domain? > becuase the current product script, is based like so: > > if ismember "groupname" then > obj.run "\\ad\sysvol\~\subscriptdept.vbs > end if > > only alot of them... like about 50 or 60, so every querry is a call to AD. > thats too much, i want/need to cut that down. > > Quote: >> Quote: >>> pass the array to a select case and fire off the subscripts inside >>> the case statement. (there are more the 60 groups is there a limit to >>> case? >> I am unaware of any limit to the number of cases in a select case >> block... >> Quote: >>> here is what i have: >>> >>> >>> /code >>> >>> dim dataarray() >>> dim data >>> dim retrv >>> dim obj >>> >>> >>> >>> set objFSO = CreateObject("Scripting.FileSystemObject") >>> set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) >>> set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) >>> set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) >>> set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) >>> >>> objTSout.writeline retrv >> what value are you expecting this statement to write into the file, given >> that retrv has yet to be assigned a value? > this is debug stuff, so I can see the vaules at that point in the script, > infact all the writelines are just for debugging to help me see output. > Quote: >> Quote: >>> retrv = checkgrp >> what value are you expecting this will assign to retrv? > here is am trying to get the array into something i can use in the select > case. I have been playing with it alot, so some things may be messy ![]() > > Quote: >> Quote: >>> 'for each obj in retrv >>> Select Case retrv >>> Case "group name here" wscript.echo "ok" >>> Case "green" document.bgColor = "green" >>> Case "blue" document.bgColor = "blue" >>> 'Case Else MsgBox "pick another color" >>> End Select >> The above will do one of three actions depending on the value of retrv >> being either "group name here", "green", or "blue". If retrv is anything >> else, nothing will happen. >> > yup, nothing happens, which i know becuase i am outputing everything at > each stage to files for me to look at. > > Quote: >> When you run this, what happens? I expect nothing as noted in my comment >> just after the end function statement... > nothing, becuase the arrays data never leaves the for loop in the > function. > Quote: >> >> Also, where is the document object defined? >> > > Quote: Quote: >>> 'next >>> >>> >>> private function checkgrp() >>> 'dim dataarray() >>> 'dim data >>> >>> >>> On Error Resume Next >>> Set objADSysInfo = CreateObject("ADSystemInfo") >>> strUser = objADSysInfo.UserName >>> Set objUser = GetObject("LDAP://" & strUser) >>> For Each strGroup in objUser.memberOf >>> Set objGroup = GetObject("LDAP://" & strGroup) >>> 'Wscript.Echo objGroup.CN >>> redim Preserve dataarray(data) >> where does "data" get its value from? >> > below, i am trying to have a dynamic array, becuase this is polling group > member ship and everyone will be different. > > > Quote: Quote: >>> dataarray(data) = objGroup.CN >>> retrv = dataarray(data) >> Assigning a value from within a function to a global variable is not a >> good idea. > i know, i was trying diffeent things to get it to work, notice the > commented out at the top of the function. > Quote: >> Quote: >>> >>> >>> 'wscript.echo dataarray(data) >>> >>> >>> 'objTSout.writeline dataarray(data) >>> 'objTSout.writeline checkgrp >>> >>> Next >>> >>> >>> >>> >>> 'objTSout2.writeline dataarray() >>> objTSout2.writeline retrv >>> objTSout4.writeline dataarray(data) >>> >>> 'wscript.echo strname >>> >>> >>> end function >> Since no value has been assigned to the name of the function, the value >> returned has nothing to do with anything the function has done. >> > i tryed doing things like checkgrp = arrayname, but it still does not > work. so i , after google and nothing, basicly am trying everything I can > think of. but since i never really played with arrays that much, and > passing data from an array in a function seems to be a black art in > vbscript.... > > > Quote: Quote: >>> wscript.echo "script has finished running" >>> >>> >>> /end code >> Neither the intent nor the execution of the code is clear to me. Since it >> contains numerous errors, I am wondering why you think it is the function >> and select case statements themselves that are responsible rather than >> your code. >> > > object, in the function get the array populted with the user who runs it, > with all the groups. then, the select case, would be formated like so: > > select case > case script_department.vbs > end case > > only like 60 cases. then those subscript, are the real login scripts for > the users. and, those subscripts, i have an inlcude function the pulls a > hashtable with everything they need to map all the drivers etc. > > > hope this clears it up some. > > Quote: >> /Al >> >> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Logon script - function array and select case not working "Nex6" <Nex6@xxxxxx> wrote in message news:alpine.WNT.2.00.0906091721360.8168@xxxxxx Quote: > This, is really the first time I tryed to mess with arrays and select > case, I do a fair amount of scripting but nothing with case and arrays. i > used a dicionary object but that was it. Quote: > On Tue, 9 Jun 2009, Al Dunbar wrote: > Quote: >> >> >> "Nex6" <Nex6@xxxxxx> wrote in message >> news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: >>> Hi all, >>> >>> I am trying to rewrite my logon scripts which are all in vbscript. the >>> scripts are written in a framework model, eg: control script,hashtable >>> script and subscripts which are for each group. >>> >>> the hash table, has all the names, and server paths, and all the scripts >>> use those names from the central hash table (via an include function) >>> (this is so if server name changes i just change the path in the hash >>> table) >>> >>> >>> this all works well, except, the function i am using for the rules in >>> the control script causes alot of querrys to AD. as there are alot of >>> groups. >> In my experience, testing group membership is expensive, no matter how >> you try to do it. >> Quote: >>> so my thinking was have a function dump all the groups into an array, >> How have you determined that this will be faster or result in fewer trips >> to the domain? > becuase the current product script, is based like so: > > if ismember "groupname" then > obj.run "\\ad\sysvol\~\subscriptdept.vbs > end if > > only alot of them... like about 50 or 60, so every querry is a call to AD. > thats too much, i want/need to cut that down. > > Quote: >> Quote: >>> pass the array to a select case and fire off the subscripts inside >>> the case statement. (there are more the 60 groups is there a limit to >>> case? >> I am unaware of any limit to the number of cases in a select case >> block... >> Quote: >>> here is what i have: >>> >>> >>> /code >>> >>> dim dataarray() >>> dim data >>> dim retrv >>> dim obj >>> >>> >>> >>> set objFSO = CreateObject("Scripting.FileSystemObject") >>> set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) >>> set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) >>> set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) >>> set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) >>> >>> objTSout.writeline retrv >> what value are you expecting this statement to write into the file, given >> that retrv has yet to be assigned a value? > this is debug stuff, so I can see the vaules at that point in the script, > infact all the writelines are just for debugging to help me see output. > Quote: >> Quote: >>> retrv = checkgrp >> what value are you expecting this will assign to retrv? > here is am trying to get the array into something i can use in the select > case. I have been playing with it alot, so some things may be messy ![]() > > Quote: >> Quote: >>> 'for each obj in retrv >>> Select Case retrv >>> Case "group name here" wscript.echo "ok" >>> Case "green" document.bgColor = "green" >>> Case "blue" document.bgColor = "blue" >>> 'Case Else MsgBox "pick another color" >>> End Select >> The above will do one of three actions depending on the value of retrv >> being either "group name here", "green", or "blue". If retrv is anything >> else, nothing will happen. >> > yup, nothing happens, which i know becuase i am outputing everything at > each stage to files for me to look at. > > Quote: >> When you run this, what happens? I expect nothing as noted in my comment >> just after the end function statement... > nothing, becuase the arrays data never leaves the for loop in the > function. > Quote: >> >> Also, where is the document object defined? >> > > Quote: Quote: >>> 'next >>> >>> >>> private function checkgrp() >>> 'dim dataarray() >>> 'dim data >>> >>> >>> On Error Resume Next >>> Set objADSysInfo = CreateObject("ADSystemInfo") >>> strUser = objADSysInfo.UserName >>> Set objUser = GetObject("LDAP://" & strUser) >>> For Each strGroup in objUser.memberOf >>> Set objGroup = GetObject("LDAP://" & strGroup) >>> 'Wscript.Echo objGroup.CN >>> redim Preserve dataarray(data) >> where does "data" get its value from? >> > below, i am trying to have a dynamic array, becuase this is polling group > member ship and everyone will be different. > > > Quote: Quote: >>> dataarray(data) = objGroup.CN >>> retrv = dataarray(data) >> Assigning a value from within a function to a global variable is not a >> good idea. > i know, i was trying diffeent things to get it to work, notice the > commented out at the top of the function. > Quote: >> Quote: >>> >>> >>> 'wscript.echo dataarray(data) >>> >>> >>> 'objTSout.writeline dataarray(data) >>> 'objTSout.writeline checkgrp >>> >>> Next >>> >>> >>> >>> >>> 'objTSout2.writeline dataarray() >>> objTSout2.writeline retrv >>> objTSout4.writeline dataarray(data) >>> >>> 'wscript.echo strname >>> >>> >>> end function >> Since no value has been assigned to the name of the function, the value >> returned has nothing to do with anything the function has done. >> > i tryed doing things like checkgrp = arrayname, but it still does not > work. so i , after google and nothing, basicly am trying everything I can > think of. but since i never really played with arrays that much, and > passing data from an array in a function seems to be a black art in > vbscript.... > > > Quote: Quote: >>> wscript.echo "script has finished running" >>> >>> >>> /end code >> Neither the intent nor the execution of the code is clear to me. Since it >> contains numerous errors, I am wondering why you think it is the function >> and select case statements themselves that are responsible rather than >> your code. >> > > object, in the function get the array populted with the user who runs it, > with all the groups. then, the select case, would be formated like so: > > select case > case script_department.vbs > end case > > only like 60 cases. then those subscript, are the real login scripts for > the users. and, those subscripts, i have an inlcude function the pulls a > hashtable with everything they need to map all the drivers etc. > > > hope this clears it up some. > > Quote: >> /Al >> >> >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Logon script - function array and select case not working "Nex6" <Nex6@xxxxxx> wrote in message news:alpine.WNT.2.00.0906091721360.8168@xxxxxx Quote: > This, is really the first time I tryed to mess with arrays and select > case, I do a fair amount of scripting but nothing with case and arrays. i > used a dicionary object but that was it. > > On Tue, 9 Jun 2009, Al Dunbar wrote: > Quote: >> >> >> "Nex6" <Nex6@xxxxxx> wrote in message >> news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: >>> Hi all, >>> >>> I am trying to rewrite my logon scripts which are all in vbscript. the >>> scripts are written in a framework model, eg: control script,hashtable >>> script and subscripts which are for each group. >>> >>> the hash table, has all the names, and server paths, and all the scripts >>> use those names from the central hash table (via an include function) >>> (this is so if server name changes i just change the path in the hash >>> table) >>> >>> >>> this all works well, except, the function i am using for the rules in >>> the control script causes alot of querrys to AD. as there are alot of >>> groups. >> In my experience, testing group membership is expensive, no matter how >> you try to do it. >> Quote: >>> so my thinking was have a function dump all the groups into an array, >> How have you determined that this will be faster or result in fewer trips >> to the domain? > becuase the current product script, is based like so: > > if ismember "groupname" then > obj.run "\\ad\sysvol\~\subscriptdept.vbs > end if > > only alot of them... like about 50 or 60, so every querry is a call to AD. > thats too much, i want/need to cut that down. function or perhaps a resource kit executable... For our logon script I developed a function that combined recursive calls to itself to deal with group nesting but it used ismember.exe to test membership in each group encountered. Once it determined whether or not user "X" was a member of group "Y", it kept that info in a dictionary object so the next time it had to test that same group it avoided the ismember.exe call. I tried about seven different versions, each using a different "is this user a member of this group" logic, and picked the one that performed the best. In the process I found that the first use of ismember.exe takes the longest time, such that subsequent uses are a lot faster. I think that is because it also caches its results somehow. Quote: > > Quote: >> Quote: >>> pass the array to a select case and fire off the subscripts inside >>> the case statement. (there are more the 60 groups is there a limit to >>> case? >> I am unaware of any limit to the number of cases in a select case >> block... >> Quote: >>> here is what i have: >>> >>> >>> /code >>> >>> dim dataarray() >>> dim data >>> dim retrv >>> dim obj >>> >>> >>> >>> set objFSO = CreateObject("Scripting.FileSystemObject") >>> set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) >>> set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) >>> set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) >>> set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) >>> >>> objTSout.writeline retrv >> what value are you expecting this statement to write into the file, given >> that retrv has yet to be assigned a value? > this is debug stuff, so I can see the vaules at that point in the script, > infact all the writelines are just for debugging to help me see output. the value of a variable that has not yet been assigned any value? Is this perhaps because you have shown only a representative sample of your script? Quote: > Quote: >> Quote: >>> retrv = checkgrp >> what value are you expecting this will assign to retrv? > here is am trying to get the array into something i can use in the select > case. I have been playing with it alot, so some things may be messy ![]() you think the case select statement is going go compare this array value (i.e. an array of individual values) with the literal string values such as "group name here"? IMHO, CASE SELECT, like IF, can only work with scalar values, not arrays. Quote: > > Quote: >> Quote: >>> 'for each obj in retrv >>> Select Case retrv >>> Case "group name here" wscript.echo "ok" >>> Case "green" document.bgColor = "green" >>> Case "blue" document.bgColor = "blue" >>> 'Case Else MsgBox "pick another color" >>> End Select >> The above will do one of three actions depending on the value of retrv >> being either "group name here", "green", or "blue". If retrv is anything >> else, nothing will happen. >> > yup, nothing happens, which i know becuase i am outputing everything at > each stage to files for me to look at. the three string values attached to the CASE statements. Quote: > > Quote: >> When you run this, what happens? I expect nothing as noted in my comment >> just after the end function statement... > nothing, becuase the arrays data never leaves the for loop in the > function. function, you are guaranteeing that, should the function ever exit, it will return no information. Quote: > Quote: >> >> Also, where is the document object defined? >> Case "green" document.bgColor = "green" The only meaning I take from this is that a variable named "document " contains a reference to an object having a property called "bgColor. Since no value is assigned to this variable, the statement, if executed, will execute in error. Now, such a variable could be created automatically in some environments, but a logon script is usually implemented as a .vbs or .wsf script where this is not the case. Quote: > > Quote: Quote: >>> 'next >>> >>> >>> private function checkgrp() >>> 'dim dataarray() >>> 'dim data >>> >>> >>> On Error Resume Next >>> Set objADSysInfo = CreateObject("ADSystemInfo") >>> strUser = objADSysInfo.UserName >>> Set objUser = GetObject("LDAP://" & strUser) >>> For Each strGroup in objUser.memberOf >>> Set objGroup = GetObject("LDAP://" & strGroup) >>> 'Wscript.Echo objGroup.CN >>> redim Preserve dataarray(data) >> where does "data" get its value from? >> > below, i am trying to have a dynamic array, becuase this is polling group > member ship and everyone will be different. dimension of an array. But when that REDIM statement is executed, the variable called "data" *MUST* contain in integer value equal to the new size of the array. Your script does not assign any value to this variable. Quote: > > > Quote: Quote: >>> dataarray(data) = objGroup.CN >>> retrv = dataarray(data) >> Assigning a value from within a function to a global variable is not a >> good idea. > i know, i was trying diffeent things to get it to work, notice the > commented out at the top of the function. yourself to trying only one of them at a time. That said, I can think of no good reason to *EVER* assign a value directly from within a function to the global variable to which the result of the function is being assigned. If this is the type of thing you are trying, it leads me to believe that you have yet to get a good overall grasp on the language. Quote: > Quote: >> Quote: >>> >>> >>> 'wscript.echo dataarray(data) >>> >>> >>> 'objTSout.writeline dataarray(data) >>> 'objTSout.writeline checkgrp >>> >>> Next >>> >>> >>> >>> >>> 'objTSout2.writeline dataarray() >>> objTSout2.writeline retrv >>> objTSout4.writeline dataarray(data) >>> >>> 'wscript.echo strname >>> >>> >>> end function >> Since no value has been assigned to the name of the function, the value >> returned has nothing to do with anything the function has done. >> > i tryed doing things like checkgrp = arrayname, but it still does not > work. so i , after google and nothing, basicly am trying everything I can > think of. but since i never really played with arrays that much, and > passing data from an array in a function seems to be a black art in > vbscript.... entire array back to the calling routine from the function. No blackness to this art at all, here is a simple example: a = "asdf" wscript.echo typename(a) wscript.echo vartype(a) a = makearray() wscript.echo typename(a) wscript.echo vartype(a) function makearray() dim av(),ix for ix = 0 to 3 redim av(ix) av(ix) = ix next makearray = av end function Of course, there is a simpler way to do the same thing in this particular case. Just delete the function and replace this line: a = makearray() with this one: a = array(0,1,2,3) In your case, the difficulty is in figuring out what information to put into the array elements. Richard made some good suggestions in that direction. Quote: > > > Quote: Quote: >>> wscript.echo "script has finished running" >>> >>> >>> /end code >> Neither the intent nor the execution of the code is clear to me. Since it >> contains numerous errors, I am wondering why you think it is the function >> and select case statements themselves that are responsible rather than >> your code. >> > > object, in the function get the array populted with the user who runs it, > with all the groups. then, the select case, would be formated like so: > > select case > case script_department.vbs > end case actually want, which, as I understand you, might look more like this: for each group in list_of_group_names select case group ' not select case case "finance" : include "script_finance.vbs" ' literal strings need to be quoted case "HR" : include "script_HR.vbs" case "IT" : include "script_IT.vbs" end SELECT ' not end case next In English: for each group the user is a member of, execute the script associated. If this is basically what you are doing, you might be able to get rid of the select case statement altogether. But this will require that the group names consist of only valid filename characters. Here's how: for each group in list_of_group_names vbsname = "script_" & group & ".vbs" if FSO.fileexist( vbsname ) then include vbsname end if next Note: this assumes that FSO contains a file system object. Alternately, you could have a dictionary object where the key is the group name (which could then be the DN or the sAMAccountName), and the value is the name of the associated script. Here's how: set vbsnames = createobject("scripting.dictionaryobject") vbsnames("dn=cn=dept\: Finance") = "\\finance_server\scripts\finance-logonscript.vbs" vbsnames("dn=cn=IT guys") = "\\common_server\logonscripts\geeksRus.vbs" etc... for each group in list_of_group_names if vbsnames( lcase(group) ).exist then include vbsnames( lcase(group) ) end if next Quote: > only like 60 cases. then those subscript, are the real login scripts for > the users. and, those subscripts, i have an inlcude function the pulls a > hashtable with everything they need to map all the drivers etc. > > > hope this clears it up some. may have made this more complicated than really necessary. /Al |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Logon script - function array and select case not working I received a copy of your post below as a personal e-mail. When I replied to ask that you keep the discussion in the group because it serves no purpose to have a private discussion, my e-mail to you bounced because the email address you supplied was not valid. Please stop this practice. /Al "Nex6" <Nex6@xxxxxx> wrote in message news:alpine.WNT.2.00.0906091721360.8168@xxxxxx Quote: > This, is really the first time I tryed to mess with arrays and select > case, I do a fair amount of scripting but nothing with case and arrays. i > used a dicionary object but that was it. > > > > On Tue, 9 Jun 2009, Al Dunbar wrote: > Quote: >> >> >> "Nex6" <Nex6@xxxxxx> wrote in message >> news:alpine.WNT.2.00.0906091532310.6772@xxxxxx Quote: >>> Hi all, >>> >>> I am trying to rewrite my logon scripts which are all in vbscript. the >>> scripts are written in a framework model, eg: control script,hashtable >>> script and subscripts which are for each group. >>> >>> the hash table, has all the names, and server paths, and all the scripts >>> use those names from the central hash table (via an include function) >>> (this is so if server name changes i just change the path in the hash >>> table) >>> >>> >>> this all works well, except, the function i am using for the rules in >>> the control script causes alot of querrys to AD. as there are alot of >>> groups. >> In my experience, testing group membership is expensive, no matter how >> you try to do it. >> Quote: >>> so my thinking was have a function dump all the groups into an array, >> How have you determined that this will be faster or result in fewer trips >> to the domain? > becuase the current product script, is based like so: > > if ismember "groupname" then > obj.run "\\ad\sysvol\~\subscriptdept.vbs > end if > > only alot of them... like about 50 or 60, so every querry is a call to AD. > thats too much, i want/need to cut that down. > > Quote: >> Quote: >>> pass the array to a select case and fire off the subscripts inside >>> the case statement. (there are more the 60 groups is there a limit to >>> case? >> I am unaware of any limit to the number of cases in a select case >> block... >> Quote: >>> here is what i have: >>> >>> >>> /code >>> >>> dim dataarray() >>> dim data >>> dim retrv >>> dim obj >>> >>> >>> >>> set objFSO = CreateObject("Scripting.FileSystemObject") >>> set objTSout = objFSO.CreateTextFile(".\loglinfunction.txt", true) >>> set objTSout2 = objFSO.CreateTextFile(".\logoutfunction.txt", true) >>> set objTSout3 = objFSO.CreateTextFile(".\top.txt", true) >>> set objTSout4 = objFSO.CreateTextFile(".\logarrayfunction.txt", true) >>> >>> objTSout.writeline retrv >> what value are you expecting this statement to write into the file, given >> that retrv has yet to be assigned a value? > this is debug stuff, so I can see the vaules at that point in the script, > infact all the writelines are just for debugging to help me see output. > Quote: >> Quote: >>> retrv = checkgrp >> what value are you expecting this will assign to retrv? > here is am trying to get the array into something i can use in the select > case. I have been playing with it alot, so some things may be messy ![]() > > Quote: >> Quote: >>> 'for each obj in retrv >>> Select Case retrv >>> Case "group name here" wscript.echo "ok" >>> Case "green" document.bgColor = "green" >>> Case "blue" document.bgColor = "blue" >>> 'Case Else MsgBox "pick another color" >>> End Select >> The above will do one of three actions depending on the value of retrv >> being either "group name here", "green", or "blue". If retrv is anything >> else, nothing will happen. >> > yup, nothing happens, which i know becuase i am outputing everything at > each stage to files for me to look at. > > Quote: >> When you run this, what happens? I expect nothing as noted in my comment >> just after the end function statement... > nothing, becuase the arrays data never leaves the for loop in the > function. > Quote: >> >> Also, where is the document object defined? >> > > Quote: Quote: >>> 'next >>> >>> >>> private function checkgrp() >>> 'dim dataarray() >>> 'dim data >>> >>> >>> On Error Resume Next >>> Set objADSysInfo = CreateObject("ADSystemInfo") >>> strUser = objADSysInfo.UserName >>> Set objUser = GetObject("LDAP://" & strUser) >>> For Each strGroup in objUser.memberOf >>> Set objGroup = GetObject("LDAP://" & strGroup) >>> 'Wscript.Echo objGroup.CN >>> redim Preserve dataarray(data) >> where does "data" get its value from? >> > below, i am trying to have a dynamic array, becuase this is polling group > member ship and everyone will be different. > > > Quote: Quote: >>> dataarray(data) = objGroup.CN >>> retrv = dataarray(data) >> Assigning a value from within a function to a global variable is not a >> good idea. > i know, i was trying diffeent things to get it to work, notice the > commented out at the top of the function. > Quote: >> Quote: >>> >>> >>> 'wscript.echo dataarray(data) >>> >>> >>> 'objTSout.writeline dataarray(data) >>> 'objTSout.writeline checkgrp >>> >>> Next >>> >>> >>> >>> >>> 'objTSout2.writeline dataarray() >>> objTSout2.writeline retrv >>> objTSout4.writeline dataarray(data) >>> >>> 'wscript.echo strname >>> >>> >>> end function >> Since no value has been assigned to the name of the function, the value >> returned has nothing to do with anything the function has done. >> > i tryed doing things like checkgrp = arrayname, but it still does not > work. so i , after google and nothing, basicly am trying everything I can > think of. but since i never really played with arrays that much, and > passing data from an array in a function seems to be a black art in > vbscript.... > > > Quote: Quote: >>> wscript.echo "script has finished running" >>> >>> >>> /end code >> Neither the intent nor the execution of the code is clear to me. Since it >> contains numerous errors, I am wondering why you think it is the function >> and select case statements themselves that are responsible rather than >> your code. >> > > object, in the function get the array populted with the user who runs it, > with all the groups. then, the select case, would be formated like so: > > select case > case script_department.vbs > end case > > only like 60 cases. then those subscript, are the real login scripts for > the users. and, those subscripts, i have an inlcude function the pulls a > hashtable with everything they need to map all the drivers etc. > > > hope this clears it up some. > > Quote: >> /Al >> >> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script that uses the DatePart & Case select | VB Script | |||
| select case does not work ... why? | VB Script | |||
| Re: Select case question | VB Script | |||
| select-string in a function not working | PowerShell | |||
| Case/Select functionality | PowerShell | |||