Page 1 of 2 12>
Topic Options
#136629 - 2005-03-29 10:12 AM OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland
Hi ALL Please Please help

If anyone can help me with my problem I would be over the moon, the problem is
Say I want to map a drive using group names I would use the following IF INGROUP("Group name") but say I want to use organisation units instead of Groups is that possible and if so want is the code

Thanks lots

Johnny

Top
#136630 - 2005-03-29 03:18 PM Re: OU instead of Groups
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I think this is what you're looking for

InContainer

Top
#136631 - 2005-03-30 09:39 AM Re: OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland
Hi thanks for the reply. I have seen that before but I have no idea how to use it I was hoping some one could show me how too. Even then I’m not sure it will do what I want
Cheers

Top
#136632 - 2005-03-30 10:19 AM Re: OU instead of Groups
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
You need to be running KiXtart 4.x hopefully 4.22 or 4.23 to run UDF code. KiXtart 3.x can not run UDF code.

There is an example of using it in the notes of the UDF which is like this.

Code:
Dim $rc
$rc = InContainer ("OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com", "Computer")
Select
case $rc[0]=1 ? "object is a member of the specified container. Run code you want to run"
case $rc[0]=2 ? "object is a member of a child container lower in the hierarchy. Run code you want to run"
case $rc[0]=0 ? "object is NOT a member of this container or a child of this container."
case $rc[0]=-1 ? "InContainer() Error - Invalid input for $NameType "
case $rc[0]=-2 ? "TranslateName() Error"
case 1 ? "Unknown return code"
EndSelect


Top
#136633 - 2005-03-30 11:42 AM Re: OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland

Thanks for your response

My Kix programming skills are far from perfect all i need to do is Map drives and create printer connections via the OU i have created the code using groups but my IT director will only use Kix if we can use OUs instead of groups for these functions. i thought it would be simple like bellow

Code:
 

break on

If InContainer('ou=Users,ou=Information Technology,OU=Dublin,dc=lab,dc=iconcr,dc=com','User')[0]
? 'T: (\\shortts\DATA)'
Use T: '\\shortts\DATA'
EndIf


But obviously I’m wrong and it is more complex, Sorry to be a pain but I would love to get this working at the moment there using Bach files Mate

Above I have the bath of the distinguished name of the user location how would the code fit

Top
#136634 - 2005-03-30 12:03 PM Re: OU instead of Groups
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, it is simple as that.
Code:
if inContainer(...)[0]
;do the stuff
endif


but I think it should be simpler.
it should be:
Code:
if inContainer(...)
;do the stuff
endif

_________________________
!

download KiXnet

Top
#136635 - 2005-03-30 12:23 PM Re: OU instead of Groups
Anonymous
Unregistered


I have tryed what you have sugested and i have put in

Code:
 
if inContainer("ou=Users,ou=Information Technology,OU=Dublin,dc=lab,dc=iconcr,dc=com","User")

USE K: "\\shortts\DATA\Department\SO-Storage-IR"

endif



but im getting ERROR: expected expresion could it be my distinguished name and if so what the best way to find out or test if it the right distinguished name im pritty sure it is but i could be missing smothing Stupid

cheers

Top
#136636 - 2005-03-30 12:36 PM Re: OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland
sorry i repyed above and was not loged in
Top
#136637 - 2005-03-30 02:22 PM Re: OU instead of Groups
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, I think you are actually lacking the udf from your script itself.
right?

add the code of incontainer (everything from function keyword to endfunction) to your script.
does not matter what the place is.
many of us even use call or include to not directly place it in the script file.

but plug that code in and try again.
and, remember, it's udf, do not alter the code anyhow or anything.
it's a self-contained "subProgram", just add it in and forget that it's there.

for more about how to use udf's, see:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81594
_________________________
!

download KiXnet

Top
#136638 - 2005-03-30 03:52 PM Re: OU instead of Groups
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Don't listen to Lonk... InContainer() returns an array so you do need to specify the first [0] element.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#136639 - 2005-03-30 04:02 PM Re: OU instead of Groups
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol!
well, I can't see everything.

lol.

btw, congrats les on post de 8888


Edited by Lonkero (2005-03-30 04:03 PM)
_________________________
!

download KiXnet

Top
#136640 - 2005-03-30 04:12 PM Re: OU instead of Groups
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Did you include the dependency TranslateName() UDF as well in your code?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#136641 - 2005-03-31 02:54 AM Re: OU instead of Groups
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Okay, don't forget you need the TranslateName UDF and the InContainer UDF either all in the same script or available via a call to them.

Code:

Dim $UsersOU
$UsersOU = InContainer('ou=Users,ou=Information Technology,OU=Dublin,dc=lab,dc=iconcr,dc=com','User')
If $UsersOU[0]=1
? 'T: (\\shortts\DATA)'
Use T: '\\shortts\DATA'
Else
? 'User was not found in the Users, Information Technology OU or some other error'
EndIf


Top
#136642 - 2005-03-31 12:09 PM Re: OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland
Thanks for your help sorry for the late reply but i based in Ireland and left work early yesterday... the pressure LoL

Thanks for your time everyone ill have to do a little research on TranslateName UDF and the InContainer UDF beacuse i really havent got a clue about them what they do and how to implement them, but i will look into it but any advice about it would be appreciated...

Top
#136643 - 2005-03-31 04:56 PM Re: OU instead of Groups
trooper Offline
Fresh Scripter

Registered: 2005-03-29
Posts: 6
Loc: Ireland
Im so confused there is a lot in this. I think I bit off more than I can chew can you have a look at the script bellow and advice me what im doing wrong or what im leaving out… sorry to bother you but im just not that good at kix
Code:


**************************************************************************************************************
**************************************************************************************************************
;FUNCTION TranslateName()
**************************************************************************************************************
**************************************************************************************************************

Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)

Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText

$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction

****************************************************************************************************
****************************************************************************************************
; InContainer() - Determines if the current account or computer is in a container
****************************************************************************************************
****************************************************************************************************

Function InContainer ("OU=Users,OU=Information Technology,OU=Dublin,DC=lab,DC=iconcr,DC=com", "Users")
Dim $Container, $CurrentContainer, $NameType, $Name1, $Name2

select
case $NameType = "Computer" $Name1 = "@Domain\@wksta$"
case $NameType = "User" $Name1 = "@LDomain\@UserID"
case 1 $Name1 = ""
endselect

if $Name1 <> ""
$Name2 = TranslateName (3, "", 3, $Name1, 1)
if $Name2[1] = 0
$CurrentContainer = substr($Name2[0], instr($Name2[0], ",")+1)
select
case $rc[0]=1 ? "object is a member of the specified container."
case $CurrentContainer=$Container $InContainer = 1, $Name2[1], $Name2[2]
case instr($Name2[0], $Container) $InContainer = 2, $Name2[1], $Name2[2]
case 1 $InContainer = 0, $Name2[1], $Name2[2]
endselect
else
$InContainer = -2, $Name2[1], $Name2[2]
endif
else
$InContainer = -1, 0, ""
endif
EndFunction

****************************************************************************************************
****************************************************************************************************

Dim $UsersOU
$UsersOU = InContainer('OU=Users,OU=Information Technology,OU=Dublin,DC=lab,DC=iconcr,DC=com','User')
If $UsersOU[0]=1
? 'T: (\\shortts\DATA)'
Use T: '\\shortts\DATA'
Else
? 'User was not found in the Users, Information Technology OU or some other error'
EndIf




any help Appreciated

Top
#136644 - 2005-03-31 05:27 PM Re: OU instead of Groups
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Are you getting an error or is it just saying that user is not in that OU? Does the user account physically live in the 'Users' OU or is it in a SubOU? What does InContainer() actually return?

Code:

Dim $UsersOU
$UsersOU = InContainer('OU=Users,OU=Information Technology,OU=Dublin,DC=lab,DC=iconcr,DC=com','User')
? $UsersOU[0]
If $UsersOU[0]=1
? 'T: (\\shortts\DATA)'
Use T: '\\shortts\DATA'
Else
? 'User was not found in the Users, Information Technology OU or some other error'
EndIf


Top
#136645 - 2005-03-31 06:07 PM Re: OU instead of Groups
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Show us the full DN of that user you are testing. What OS are you testing this on?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#136646 - 2005-03-31 09:09 PM Re: OU instead of Groups
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You have this line in the InContainer UDF.
Quote:


case $rc[0]=1 ? "object is a member of the specified container."




I do not see that line in the version in the UDF Library.


Please document exactly what you are or are not getting as returned values. What is the exact nature of the failure?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#136647 - 2005-03-31 09:35 PM Re: OU instead of Groups
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Nice catch there Howard.

Trooper - please don't modify any UDF until you've become more familiar with KiXtart and understand the implcations of your modifications. UDF are designed to be used sort of like a black-box solution. You call them and provide data for them, but don't modify them.

Please copy this code below into WORDPAD, then copy again from WORDPAD into either Notepad or some other ASCII editor and save the file as CONTAINER.KIX then call it from DOS console like this so you can view the returned data.
Then report back what you saw on screen.
Please use KiXtart 4.22 or 4.23


KIX32.EXE CONTAINER.KIX

Dim $UsersOU
$UsersOU = InContainer('OU=Users,OU=Information Technology,OU=Dublin,DC=lab,DC=iconcr,DC=com','User')
Select
Case $UsersOU[0]=1
? "object is a member of the specified container."
? 'T: (\\shortts\DATA)'
Use T: '\\shortts\DATA'
? 'Mapping T: drive ERR: ' + @ERROR + ' ' + @SERROR
Case $UsersOU[0]=2
? "object is a member of a child container lower in the hierarchy."
Case $UsersOU[0]=0
? "object is NOT a member of this container or a child of this container."
Case $UsersOU[0]=-1
? "InContainer() Error - Invalid input for $NameType "
Case $UsersOU[0]=-2
? "TranslateName() Error"
Case 1
? "Unknown return code"
EndSelect


Function InContainer ($Container, $NameType)
Dim $Container, $CurrentContainer, $NameType, $Name1, $Name2
Select
Case $NameType = "Computer" $Name1 = "@Domain\@wksta$"
Case $NameType = "User" $Name1 = "@LDomain\@UserID"
Case 1 $Name1 = ""
EndSelect
If $Name1 <> ""
$Name2 = TranslateName (3, "", 3, $Name1, 1)
If $Name2[1] = 0
$CurrentContainer = SubStr($Name2[0], InStr($Name2[0], ",")+1)
Select
Case $CurrentContainer=$Container $InContainer = 1, $Name2[1], $Name2[2]
Case InStr($Name2[0], $Container) $InContainer = 2, $Name2[1], $Name2[2]
Case 1 $InContainer = 0, $Name2[1], $Name2[2]
EndSelect
else
$InContainer = -2, $Name2[1], $Name2[2]
EndIf
else
$InContainer = -1, 0, ""
EndIf
EndFunction


Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CreateObject ("NameTranslate")
$Error = @ERROR
$ErrorText = @serror
If $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @ERROR
$ErrorText = @serror
If $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @ERROR
$ErrorText = @serror
If $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @ERROR
$ErrorText = @serror
EndIf
EndIf
EndIf
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction


Top
#136648 - 2005-04-13 07:44 AM Re: OU instead of Groups
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
not sure if your supplied example is exactly as you are using it, but you need to make sure you comment out the asterisks..
; *********
; FUNCTION TranslateName()
; *********
_________________________
John
LM Contractor
One of the 2 dads

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 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.072 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

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