I can not get the function incontainer to work.

the workstations is placed in the AD according to my classrooms.

eks.

SOSF0889-kaeld
SOSF0890-kaeld is in OU=kaeld,OU=lokaler-fr,DC=SOSVA,DC=ELEV

SOSF0721-L208
SOSF0729-L208 is in .208.lokaler-fr.sosva.elev

but the script install all printers.

can anyone help me.


the script
Code:
; ===========================================================================================
;
; Script Information
;
; Title: partiel Loginscript for social- og sundhedsskolen i Vejle Amt
; Author: John mortensen (C) 2004
; Description: use for add printer bruges
;
;
; ===========================================================================================
;****************************************************************
;* printer for lokale kaelder *
;****************************************************************

$rc = InContainer ("OU=@WKSTA,OU=kaelder,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\pkaelder")
SetDefaultPrinter ("\\SOSFELEV\pkaelder")=0
endif
;****************************************************************
;* printer for lokale 208 *
;****************************************************************


$rc = InContainer ("OU=@WKSTA,OU=208,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\p208")
SetDefaultPrinter ("\\SOSFELEV\p208")=0
endif

;****************************************************************
;* printer for lokale 117 *
;****************************************************************


$rc = InContainer ("OU=@WKSTA,OU=117,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\p117")
SetDefaultPrinter ("\\SOSFELEV\p117")=0
endif

;****************************************************************
;* printer for lokale studie 1 *
;****************************************************************


$rc = InContainer ("OU=@WKSTA,OU=studie1,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\pstudie1")
SetDefaultPrinter ("\\SOSFELEV\pstudie1")=0
endif

;****************************************************************
;* printer for lokale studie 2 *
;****************************************************************
$rc = InContainer ("OU=@WKSTA,OU=studie2,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\pstudie2")
SetDefaultPrinter ("\\SOSFELEV\pstudie2")=0
endif

;****************************************************************
;* printer for lokale natur *
;****************************************************************
$rc = InContainer ("OU=@WKSTA,OU=natur,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
select
case $rc[1] ? "1";object is a member of the specified container."
case $rc[2] ? "2";object is a member of a child container lower in the hierarchy."
case $rc[0] ? "0";object is NOT a member of this container or a child of this container."
case 1 ? "Error"
endselect

if $rc[1]
AddPrinterConnection ("\\SOSFELEV\pnatur")
SetDefaultPrinter ("\\SOSFELEV\pnatur")=0
endif




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]

$SELECTION =MESSAGEBOX("$Currentcontainer",0)
IF $SELECTION = 1

endif
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


$SELECTION =MESSAGEBOX("$InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType", 0)
IF $SELECTION = 1

endif
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")

$SELECTION =MESSAGEBOX("$nametranslate",0)
IF $SELECTION = 1

endif
$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



Edited by Howard Bullock (2005-04-08 01:18 PM)