Page 1 of 2 12>
Topic Options
#147584 - 2005-09-12 02:57 PM If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
I need a script that checks if a user is member of a group that contains a certain word. Let's say I need to know where a user is admin and I have groups like "New York Admin", "Dallas Admin" etc, so I want to enumerate the membership of all groups with Admin in the name.

can someone help me PLEASE!

thanx Rick


Edited by talismaniak (2005-09-12 03:00 PM)

Top
#147585 - 2005-09-12 03:07 PM Re: If groupname contains...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Code:

$localgroups = getobject('WinNT://' + @wksta)
$localgroups.filter = 'group',''
for each $group in $localgroups
if instr($group.name,'admin')
;this local group has 'admin' in it's name
? $group.name
endif
next


Top
#147586 - 2005-09-12 05:27 PM Re: If groupname contains...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmmm...
Code:

;semi code generated on the fly
for each $group in enumgroups()
if instr($group,"admin")
$group " has admin in it" ?
endif
next

_________________________
!

download KiXnet

Top
#147587 - 2005-09-12 09:22 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
Thanx for the code, I managed to enum the groups too, but this looks better.. How can I put those "admin" groups in an array so that I can use the found groups later in my script?? I allready found a enumgrouparray function on the net, but I can't get it to work... Can you help me out again??
Top
#147588 - 2005-09-12 10:09 PM Re: If groupname contains...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Code:

$localgroups = getobject('WinNT://' + @wksta)
$localgroups.filter = 'group',''

DIM $admingroups[0]

for each $group in $localgroups
if instr($group.name,'admin')
;this local group has 'admin' in it's name
$admingroups[$i] = $group
$i = $i + 1
redim preserve $admingroups[$i]
EndIf
next

If $i
redim preserve $admingroups[$i-1]
Else
$admingroups=0
EndIf

for each $group in $admingroups
? $group.name
next


Top
#147589 - 2005-09-12 10:15 PM Re: If groupname contains...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jooel's use of EnumGroup() will only enumerate groups the current user is a member of, so IMHO it does not meet the req. Bryce's, OTOH does.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147590 - 2005-09-12 11:42 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
Hi, thank you all.. Sorry for my bad English, but I need this for the current users membership only. I will explain why: I want to check which rights the person has and then supply him with an options menu based on that query (applicable to every query I choose). In this example "admin".

Let's say he is member of Miami Admins and New York Admins. He starts the script and the script runs a query on "admin". It returns those two groups that will appear in his menu like

"Select your options:
1. Miami Admin options
2. New York Admin options"

This script would make my life so much easier ;-))

Top
#147591 - 2005-09-12 11:56 PM Re: If groupname contains...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so the enumgroup it would be

still semi code:
Code:

dim $adminGroups[0]
for each $group in enumgroup()
if instr($group,"admin")
$adminGroups[ubound($adminGroups)] = $group
redim preserve $adminGroups[ubound($adminGroups)+1]
endif
next
redim preserve $adminGroups[ubound($adminGroups)-1]

_________________________
!

download KiXnet

Top
#147592 - 2005-09-13 12:10 AM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
Jooel, I get an error when I run your code. It says: ERROR : invalid method/function call: missing required parameter 1! on line 2...

How can I use the groups within the script to build the menu?

Top
#147593 - 2005-09-13 01:34 AM Re: If groupname contains...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol, like said, my code is semi code.
see kixtart manual for enumgroup() usage.
_________________________
!

download KiXnet

Top
#147594 - 2005-09-13 02:14 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
Damn I can't get it to work, I'm learning scripting by the minute, but I'm still unable to understand how i use the groupnames at a later stage in the script.
Top
#147595 - 2005-09-13 04:47 PM Re: If groupname contains...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, my script puts them in array.
so to access them you would use:
$groupNames[0] for the first, $groupNames[1] for the second and so on.

or just simply:
for each $groupName in $groupNames

for each pulls each element of given array one at a time.

and you could always post what you have this far and let us look at it.
_________________________
!

download KiXnet

Top
#147596 - 2005-09-15 05:50 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
So I use the script Bryce wrote, I should be able to display a group witth the command "? $admingroups[1]"? This results in "IDispatch pointers not allowed in expressions!"
Top
#147597 - 2005-09-15 07:54 PM Re: If groupname contains...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
you can not array variables in side of a string..

? "admin group = " + $admingroups[1]

Top
#147598 - 2005-09-15 11:03 PM Re: If groupname contains...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
why you running bryce's code as you said before it's not what you were after?
_________________________
!

download KiXnet

Top
#147599 - 2005-09-16 02:39 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
I'm running that script just to figure out how I can make use of the enumerated groups. What I want is when a user logs on, the groups containing a certain word are shown, then a user can make his selection which one he wants to start... So I thought:

for each $group in $admingroups
? $group.name
Get $x
? users selection is $admingroups[$x]

and then something like:
net use g: \\server\$admingroup[$x]


Must be possible somehow...

Top
#147600 - 2005-09-16 02:53 PM Re: If groupname contains...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Is your keyboard missing the " and + keys? You need to start wrapping strings in quotes and concatenating vars properly.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147601 - 2005-09-16 03:03 PM Re: If groupname contains...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here's one way to do it, this presents groups with the letter "o" in them:
Code:
Break ON
$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")

Dim $iIndex, $sGroup, $sAllGroups

$iIndex=0
$sGroup=EnumGroup($iIndex)
While Not @ERROR AND $sGroup
$iIndex=$iIndex+1
If InStr($sGroup,"o") $sAllGroups=$sAllGroups+@CRLF+$sGroup EndIf
$sGroup=EnumGroup($iIndex)
Loop

$sAllGroups=Split($sAllGroups,@CRLF)
For $iIndex=1 to UBound($sAllGroups) CStr($iIndex)+". "+$sAllGroups[$iIndex]+@CRLF Next
"Enter a number between 1 and "+($iIndex-1)+" : " GetS $iIndex
$iIndex=Val($iIndex)
If $iIndex>0 AND $iIndex<UBound($sAllGroups)
"You selected group '"+$sAllGroups[$iIndex]+@CRLF
Else
"You made an invalid selection"+@CRLF
EndIf


Top
#147602 - 2005-09-16 03:57 PM Re: If groupname contains...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Note how Bryce and Richard make proper use of the " and + keys.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147603 - 2005-09-16 04:14 PM Re: If groupname contains...
talismaniak Offline
Fresh Scripter

Registered: 2005-09-12
Posts: 12
Brilliant!! thanks... Now I can think of the next step.
Top
Page 1 of 2 12>


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

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.093 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

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