Page 1 of 1 1
Topic Options
#69235 - 2002-08-20 11:14 PM Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
I'm not looking for code or anything, just more logic on how to create a menu like this:

Please select from the following:
1 Item 1
2 Item 2
3 Item 3
Selection:

The problem is that the menu should search through multiple AD groups, and users are assigned to more than one AD group. The Items are different shares that will be mapped. The only items I want listed are items that match their AD group membership. Could be 4,5,6, up to 10 items.

I only want people to have 2 mapped drives. The drive they select from their memberships and their homeshare.

If I need more explanation, please let me know.

Any info on how to do something like this would be greatly appreciated... Thanks!
Ben

Top
#69236 - 2002-08-20 11:23 PM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would go with enumgroup as it's the user currently you want to enum the groups for.
ref: http://www.gwspikval.com/jooel/manual/kix410.html#ENUMGROUP

For those enumerated groups it should not be too hard.

now, it's your turn to ask if something isn't clear.

cheers.

[ 20. August 2002, 23:25: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#69237 - 2002-08-21 12:17 AM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
If I use an ENUMGROUP, how could I extract the groups that the user is a member of to display? Does it keep a default array (like perl $_) of groups that the user is in? I guess I don't follow on what to do afterwards....
Top
#69238 - 2002-08-22 12:32 AM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you just run the code:
code:
$=-1
do $=$+1
$f=enumgroup($) ? $f
until $f=""

you will get the idea.
the array of the groups is allways retrievable with enumgroup.

but if you don't have menu selection for all groups you could just use ingroup to make your menu.
code:
if ingroup("domain admins")
$menulist=$menulist+",Administrators"
....
endif

this way you evaluate all groups you want. not all groups the user might be in.

then, making the menu would be:
code:
$menulist=split($menulist,",")
for $c=1 to ubound($menulist)
? $c "." $menulist[$c]
next

I think it's pretty much easier with ingroup.
anyway, with enumgroup you probably would need to play with some sort of array.

cheers.
_________________________
!

download KiXnet

Top
#69239 - 2002-08-21 10:30 PM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
Okay I used the lines:

$=-1
do $=$+1
$f=enumgroup($) ? $f
until $f=""
sleep 5

It displays the memberships, now I need to move them into an array... Would something like this work to place it into an array?

$=-1
do $=$+1
$f=enumgroup($) ? $f
;place memberships for user into array
$array[$index]=$f
$index=$index + 1
until $f=""

From there I would need to place the array into a menu selection. Am I on the right train of thought, or am I way off base??? As you can tell I'm not a programmer, but I like to try every now and then.

Top
#69240 - 2002-08-21 10:44 PM Re: Arrays and Menu's
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Why do you want to limit them to two mapped drives only?

How do you store the selection that the user makes, or does the user have to select drives every time he logs in?

How does the user change the mapped drives?

Personally, I would assign the drives according to group membership and not give the user any choice. The less choices a user has the less trouble for the administrator.
_________________________
There are two types of vessels, submarines and targets.

Top
#69241 - 2002-08-21 10:51 PM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I didn't say it in the last post well enough, but the enumgroup returns an array.
as it's indexed already.
if you want to make it an array, and want it place them directly to it you have in your code, you would need to make two queries. first to let you know how big your array is and so on.

easiest, if you really want it this way (I bet you don't want to have all those local groups there too) instead of ingroupping:
place the groups in string.
divide that string into an array with split()

so, to have an array, it would look like:
code:
$=-1
do $=$+1
$f=enumgroup($) ? $f
$grouparray=$grouparray+","+$f
until $f=""

$grouparray=split($grouparray)

for $c=0 to ubound(menulist)
? $c "." menulist[$c]
next



[ 21. August 2002, 23:13: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#69242 - 2002-08-22 12:17 AM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
We want to limit students to have one homeshare and one mapped drive to the class that they will be working on when logged in. Just to restrict the user/student. They will have to choose a class every time they log in. This wasn't my idea, but my boss wants it this way.
Example:
BeginningKeyboarding is a AD Group,
\\Server\BeginningKeyboarding is a share (same name as AD group). What I would like to do is have BeginningKeyboarding a menu selection and then have a mapping statement like:
use v: \\Server\$classselection
instead of creating 50 if statements for each class (like if $selectedclass = 3 then use v: \\server\begkey).
Sorry if I am not explaining this very well. I thought about creating an array like:
$classarray = BegKey CompSci InfoSys ect....
and then splitting them by " ", but I'm not sure if that's what I'm looking for or not.... Any help is greatly appreciated along with comments for the code so I can learn with it instead of just copying and pasting.... Thanks!

Ben

Top
#69243 - 2002-08-22 12:35 AM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, so...
your goal mostlikely is with enumgroup.

anyway, does the class names have anything to do with the groupnames?

if not, you will still need to use for simpicity's sake the ingroup.

or just write a ini-file with the group names as valuenames and share to map as valuedata.

this way you can do all the stuff in one loop with ingroup...

anyway, it's a little simpler if you have class groups named so they can be identified to some class' share.
the best would be a group named same as the class' share.

{edit}
btw, we all have known uttleast one PHB in our lifes. not bad. as we just keep our minds focused on DNRC [Big Grin]

[ 22. August 2002, 00:37: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#69244 - 2002-08-22 01:22 AM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
I do have it setup so that the group names are exactly the same as the class shares. I would like to do it with one loop. I don't follow you on how to create the ini file or how to set it up this way... Could you explain this a little further?
Top
#69245 - 2002-08-22 03:36 AM Re: Arrays and Menu's
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
To recap:

1) You have students taking one or more classes (excludes arranging users in groups, since user might be in multiple groups)
2) Each student will only get the appropriate class mapping
3) Each student will get the homeshare
4) Computers can be used for more than one class (would exclude arranging computers in groups in AD)

Solution:
1) Create hidden shares for the homedrives, preferably based on the username. Thus, you'd end up with local directories on a server like
D:\USERS\USER1 and hidden share USER1$
D:\USERS\USER2 and hidden share USER2$

2) Create hidden shares for the class directories like
E:\CLASSES\BEGINNINGKEYBOARDING with hidden share BEGINNINGKEYBOARDING$
E:\CLASSES\HACKING101 with hidden share HACKING101$

3) Create a CLASSES.INI file in the same directory where the login script is. Format:
[CLASSES]
BEGINNINGKEYBOARDING=\\server1\beginningkeyboarding$
HACKING101=\\server2\hacking101$

Basically, you assign the share to the appropriate classname

Then you can use READPROFILESTRING to read in the list of classes. Have the student choose a class and then read the drive mapping for that class. Basic code would look like this:
code:
$classes=readprofilestring(@scriptdir+'\classes.ini','Classes','')
$classes=split($classes,chr(10))
$selection=-1
do
cls
for $class=0 to ubound($classes)
? ''+$class+') '+$classes[$class]
next
gets $selection
$selection=val($selection)
until $selection>=0 and $selection<=ubound($classes)
$class=$classes[$selection]
$classmapping=readprofilestring(@scriptdir+'\classes.ini','Classes',$class)

net use H: $classmapping
if @error
? 'Error mapping drive H: to '+$classmapping
? 'Error code: '+@ERROR+' - '+@SERROR
endif

$homeshare='\\server\'+@USERID+'$$'
net use I: $homeshare
if @error
? 'Error mapping drive I: to '+$homeshare
? 'Error code: '+@ERROR+' - '+@SERROR
endif



[ 22. August 2002, 03:37: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#69246 - 2002-08-22 11:32 PM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
I used that and it's close to what I want... But not exactly. That gives me a list of all 128 classes and my selection line prompt is: 129) I think I can figure out the prompt once I completely understand the code. But what I want is to display only the classes that the student is a member too. The AD groups are named the same as the share names. How would I display just those groups instead of the whole file?
Top
#69247 - 2002-08-22 11:57 PM Re: Arrays and Menu's
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Then you will have to enumerate the groups for the user. The code would now look like this:
code:
$groupcount=0
do
redim preserve $groups[$groupcount]
$group=ENUMGROUP($groupcount)
$groups[$groupcount]=$group
$groupcount=$groupcount+1
until len($group)=0
if $groupcount
$groupcount=$groupcount-1
endif

$selection=-1
do
cls
for $group=0 to ubound($groups)
? ''+$group+') '+$groups[$group]
next
gets $selection
$selection=val($selection)
until $selection>=0 and $selection<=ubound($groups)

$class=$groups[$selection]

$classmapping=readprofilestring(@scriptdir+'\classes.ini','Classes',$class)
if $classmapping
net use H: $classmapping
if @error
? 'Error mapping drive H: to '+$classmapping
? 'Error code: '+@ERROR+' - '+@SERROR
endif
else
? 'Class '+$class+'does not have a drive mapping'
endif

$homeshare='\\server\'+@USERID+'$$'
net use I: $homeshare
if @error
? 'Error mapping drive I: to '+$homeshare
? 'Error code: '+@ERROR+' - '+@SERROR
endif

The group enumeration is straight out of the KiXtart manual and i haven't tested the code but it should give you a start.
_________________________
There are two types of vessels, submarines and targets.

Top
#69248 - 2002-08-23 12:06 AM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...

this is getting way too complicated. it surely is simple task with simple solution.

jens, should we golf on it?
_________________________
!

download KiXnet

Top
#69249 - 2002-08-23 12:10 AM Re: Arrays and Menu's
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Hmm, I still see it as a simple solution based on the problem. However, one could definitely come up with a different way by reorganizing the whole mapping architecture.

For example, create user accounts for each class. Then the user logs in with the class account and gets prompted for his username and password which then create a mapping to the personal share.

Would definitely score less [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#69250 - 2002-08-23 12:22 AM Re: Arrays and Menu's
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeah, like with:
srnd(@msecs)
if ingroup(rnd())
exit 0
endif

[Big Grin] [Big Grin] [Big Grin]
_________________________
!

download KiXnet

Top
#69251 - 2002-09-11 02:15 AM Re: Arrays and Menu's
jamen Offline
Fresh Scripter

Registered: 2002-05-31
Posts: 13
Finally came up with a solution... Couldn't have done it with all of your guy's help!! Thanks, I owe you all a round of beers, no make it two...

Ben
code:
 
use v: /delete
use w: @homeshr

if exist(c:\temp\temporary.txt)
del "c:\temp\temporary.txt"
endif
if exist(c:\temp\classes.ini)
del "c:\temp\classes.ini"
endif
if exist(c:\temp\remove.txt)
del "c:\temp\remove.txt"
endif

IF @inwin = 1
Sendkeys("~{TAB}")
ENDIF

Open(1,"c:\temp\temporary.txt",5)
Open(2,"c:\temp\classes.ini",5)
Open(3,"c:\temp\remove.txt",5)

writeline(2,"[classes]" + Chr(13)+ Chr(10))

;This part writes all of the groups into a file
$groupcount=0
do
redim preserve $groups[$groupcount]
$group=ENUMGROUP($groupcount)
$groups[$groupcount]=$group
writeline(1,$group + Chr(13) + Chr(10))
$groupcount=$groupcount+1
until len($group)=0

close(1)
close(2)
close(3)

open(1,"c:\temp\temporary.txt",2)
open(3,"c:\temp\remove.txt",4)

$remdomuser="xxx\Domain Users"
$remdomuserlen=Len($remdomuser)
$remdomstud="xxx\Students_Global"
$remdomstudlen=len($remdomstud)
$deleteme=Readline(1)
while @ERROR=0
if Left($deleteme,$remdomuserlen)=$remdomuser
$remdomuser="trash"
writeline(3,$remdomuser + Chr(13) + Chr(10))
$deleteme=Readline(1)
endif
if Left($deleteme,$remdomstudlen)=$remdomstud
$remdomstud="trash"
writeline(3,$remdomstud + Chr(13) + Chr(10))
$deleteme=Readline(1)
else
writeline(3,$deleteme + Chr(13) + Chr(10))
$deleteme=Readline(1)
endif
loop

close(1)
close(3)

;This is my test area below

Open(3,"c:\temp\remove.txt",2)
Open(2,"c:\temp\classes.ini",4)

$dom="xxxxxxx\"
$domlen=Len($dom)
$strip=Readline(3)
while @ERROR = 0
If Left($strip,$domlen)=$dom
$strip=SubStr($strip,$domlen+1)
"Group stripped of domain = " ? $strip
writeline(2,$strip + "=\\Server\"+ $strip + Chr(13) + Chr(10))
$strip=ReadLine(3)
? $strip
Else
$strip=ReadLine(3)
? $strip
Endif
loop
close(3)
close(2)

;This is my test area above

;This part reads and displays a menu
Open(2,"c:\temp\classes.ini",2)
$classes=readprofilestring("c:\temp\classes.ini",'Classes','')
$classes=split($classes,chr(10))
$selection=-1
do
cls
for $class=1 to ubound($classes)
? ''+$class+') '+$classes[$class-1]
next
"

Type in a class number or press enter for none. If you select
the wrong class, you will have to log out and log back in.

Enter Selection : "
gets $selection

$selection=val($selection)
until
$selection>=0 and $selection=ubound($classes)

$selection=$selection - 1

$class=$classes[$selection]
$classmapping=readprofilestring(@scriptdir+'\classes.ini','Classes',$class)
use v: $classmapping
if @error ? 'Error mapping drive v: to '+$classmapping
? 'Error code: '+@ERROR+' - '+@SERROR
endif
close(1)
close(2)
del "c:\temp\temporary.txt"
del "c:\temp\classes.ini"
del "c:\temp\remove.txt"

[Moderator (Sealeopard)]: Fixed incorrect code tags

[ 11. September 2002, 17:41: Message edited by: sealeopard ]

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org