#137551 - 2005-04-08 09:49 AM
incontainer
|
johndk
Fresh Scripter
Registered: 2004-11-25
Posts: 12
Loc: Denmark- horsens
|
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)
|
|
Top
|
|
|
|
#137552 - 2005-04-08 10:53 AM
Re: incontainer
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
well taking just this portion my guess is that it returns an error if anything
$rc = InContainer ("OU=@WKSTA,OU=kaelder,ou=lokaler-fr,DC=sosva,DC=elev","Computer")
Doubt that is the correct AD path to your computers.
Then, once the correct path is used, you need to place the code you want to run within the SELECT statements.
Using IF statements needs to be done logically as well.
Lets try some very basic small script first to make sure we can get back the expected data, then move on to having it do something based on that.
Try the Translatename UDF located here http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82426
That should help you to get the correct path.
|
|
Top
|
|
|
|
#137553 - 2005-04-08 11:47 AM
Re: incontainer
|
johndk
Fresh Scripter
Registered: 2004-11-25
Posts: 12
Loc: Denmark- horsens
|
It does not give any error and it adds every printer 
adn AD looks like this domain sosva.elev | |-lokaler-fr (OU) | |-kaelder (OU) | | | |- SOSF0889-KAELD (Computer) | |- SOSF0890-KAELD (Computer) | |-208 (OU) | |- SOSF0721-L208 (Computer) |- SOSF0729-L208 (Computer)
the computers are in the OU where they are standing
|
|
Top
|
|
|
|
#137554 - 2005-04-08 12:39 PM
Re: incontainer
|
johndk
Fresh Scripter
Registered: 2004-11-25
Posts: 12
Loc: Denmark- horsens
|
Thank yuo for the translatename. I had an error i this.
Now i have this problem.  error: unexpected command! line 130 "If $name2[1]=0
the translatename returns "cn=SOSF0285-STUD2,OU=studie2,OU=lokaler-fr,DC=sosva,DC=elev,0,Handlingen er gennemført"
|
|
Top
|
|
|
|
#137555 - 2005-04-08 01:31 PM
Re: incontainer
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
First thing to do is get the most recent copy on InContainer from the UDF Library. It was updated recently. I will look more closely at the code when I get into the office this morning.
|
|
Top
|
|
|
|
#137556 - 2005-04-08 02:31 PM
Re: incontainer
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This code works for me. Code:
Break on
;FUNCTION InContainer() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;VERSION 1.5 ; ;ACTION Determines if the current NT4 account name type is a member of a specific container (OU, Computers, etc) ; in Active Directory ; ;SYNTAX InContainer ($Container, $NameType) ; ;PARAMETERS $Container (Required) ; - String value ; Dinstinghished name of the container to check. This must be the fully qualified DN to ; accurately make a determination. ; ; $NameType (Required) ; - String value ; "Computer" or "User" are currently the only valid values ; ;REMARKS This function returns true if the object being checked in the the specified container ; or a child container of that specified. ; ;RETURNS An ARRAY of three values: ; InContainer return code ; 1 = object is a member of the exact container specified. ; 2 = object is a member of the container hierarchy. ; 0 = object is not a member of the container hierarchy. ; -1 = Invalid input for $NameType ; -2 = Error in TranslateName ; TranslateName ErrorCode ; TranslateName ErrorText ; ;DEPENDENCIES OS: Active Directory aware client ; Other Functions: TranslateName() ; ;EXAMPLES $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." ; case $rc[0]=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 $rc[0]=-1 ? "InContainer() Error - Invalid input for $NameType " ; case $rc[0]=-2 ? "TranslateName() Error" ; case 1 ? "Unknown return code" ; endselect ; ; Function InContainer ($Container, $NameType) Dim $CurrentContainer, $Name1, $Name2, $Found
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
$Found=0 while $Found=0 $commaloc = instr($Name2[0], ",") if $commaloc > 1 if substr($Name2[0],$commaloc-1,1) = "\" $Name2[0] = substr($Name2[0], $commaloc+1) else $Found=1 $CurrentContainer = substr($Name2[0], $commaloc+1) endif else $Found=1 endif loop
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() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;VERSION 2.0 ; ;ACTION Translates from one name type to another. Good for converting an NT4 name ; like domain\user into an LDAP distinguished name or the reverse. ; ;SYNTAX TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType) ; ;PARAMETERS $InitType (Required) ; - Integer value ; 1 = ADS_NAME_INITTYPE_DOMAIN ; Initializes a NameTranslate object by setting the domain that the object will bind to. ; ; 2 = ADS_NAME_INITTYPE_SERVER ; Initializes a NameTranslate object by setting the server that the object will bind to. ; ; 3 = ADS_NAME_INITTYPE_GC ; Initializes a NameTranslate object by locating the global catalog to which the object ; will bind. ; ; $BindName (Required) ; - String value ; If an $InitType = 3 (ADS_NAME_INITTYPE_GC), then the $BindName = "". ; InitTypes 1 and 2 require a name of a domain or server to be input. ; Note: "" may default to the current server or domain. ; ; $LookupNameType (Required) ; - Integer value ; ; $LookupName (Required) ; - String value see below ; ; $ReturnNameType (Required) ; - Integer value see below ; ; Documentation of Name Types. Lookup the more info on http://MSDN.Microsoft.com ; Not all name types work. "1", "2", and "3" have been the most useful. ; ; 1 = ADS_NAME_TYPE_1779 ; Name format as specified in RFC 1779. For example, "CN=Jane Doe,CN=users, DC=Microsoft, DC=com". ; ; 2 = ADS_NAME_TYPE_CANONICAL ; Canonical name format. For example, "Microsoft.com/Users/Jane Doe". ; ; 3 = ADS_NAME_TYPE_NT4 ; Account name format used in Microsoft® Windows© NT® 4.0. For example, "Microsoft\JaneDoe". ; ; 4 = ADS_NAME_TYPE_DISPLAY ; Display name format. For example, "Jane Doe". ; ; 5 = ADS_NAME_TYPE_DOMAIN_SIMPLE ; Simple domain name format. For example, "JaneDoe@Microsoft.com". ; ; 6 = ADS_NAME_TYPE_ENTERPRISE_SIMPLE ; Simple enterprise name format. For example, "JaneDoe@Microsoft.com". ; ; 7 = ADS_NAME_TYPE_GUID ; Global Unique Identifier format. For example, {95ee9fff-3436-11d1-b2b0-d15ae3ac8436}. ; ; 8 = ADS_NAME_TYPE_UNKNOWN ; Unknown name type. The system will try to make the best guess. ; ; 9 = ADS_NAME_TYPE_USER_PRINCIPAL_NAME ; User principal name format. For example, "JaneDoe@Fabrikam.com". ; ; 10 = ADS_NAME_TYPE_CANONICAL_EX ; Extended canonical name format. For example, "Microsoft.com/Users Jane Doe". ; ; 11 = ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME ; Service principal name format. For example, "www/www.microsoft.com@microsoft.com" ; ; 12 = ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME ; A SID string, as defined in the Security Descriptor Definition Language (SDDL), for either ; the SID of the current object or one from the object's SID history. ; For example, "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)" For more information see ; Security Descriptor String Format under "Security" in the Microsoft Platform SDK documentation. ; ;REMARKS Not name types seem to work. ; ;RETURNS This function returns an ARRAY of three values: ; Name of the type specified by $ReturnNameType (String) ; Error number (Long Integer) ; Error text (String). ; ;DEPENDENCIES OS: Active Directory aware client ; ;EXAMPLES $DN = TranslateName (3, "", 3, "@Domain\@wksta$", 1) ; ? "DN = " + $DN[0] ; ? "Error = " + $DN[1] ; ? "ErrorText = " + $DN[2] ; ; $DN = TranslateName (3, "", 3, "@LDomain\@userid", 1) ; ? "DN = " + $DN[0] ; ? "Error = " + $DN[1] ; ? "ErrorText = " + $DN[2] ; ; Function TranslateName ($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
$rc = InContainer ("OU=test,OU=9826,OU=Organizations,DC=us,DC=mydomain,DC=com", "Computer") select case $rc[0]=1 ? "object is a member of the specified container." case $rc[0]=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 $rc[0]=-1 ? "InContainer() Error - Invalid input for $NameType " case $rc[0]=-2 ? "TranslateName Error" + $rc[1] + " " + $rc[2] case 1 ? "Unknown return code:" + $rc[0] endselect
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|