MrYretix
(Lurker)
2007-04-16 12:25 PM
AddPrinter Problem

Hello

I am now busy to make scripts with kixtart. I it quite good, only that I now have a problem with the coupling of printers in my departments in my company.

The company has been classified in deparments and each department has his own printer. In my script I give that each department must have his own printer.

When I do that I get a error.
My script is:

 Code:

; Printers toewijzen aan gebruikers per afdeling

; Printers voor Afdeling Inkoop
IF InOU("Afdeling Inkoop", 1)
	IF AddPrinterConnection ("\\176server\Afdeling Inkoop") = 0
		SetDefaultPrinter ("\\176server\Afdeling Inkoop")
IF InOU("Afdeling Inkoop", 1)
	IF AddPrinterConnection ("\\176server\Secretariat") = 0
	EndIf

; Printers voor Afdeling Verkoop
IF InOU("Afdeling Verkoop", 1)
	IF AddPrinterConnection ("\\176server\Afdeling Verkoop") = 0
		SetDefaultPrinter ("\\176server\Afdeling Verkoop")
IF InOU("Afdeling Inkoop", 1)
	IF AddPrinterConnection ("\\176server\Hoofd Administratie") = 0
	EndIf



What do I wrong, what must I do so that it well does.
I hope that you my can help.

Thanks!



Glenn BarnasAdministrator
(KiX Supporter)
2007-04-16 01:44 PM
Re: AddPrinter Problem

Do you have a function defined called "InOU"? Can you post the code, or a reference to it if it's already on the BBS?

Also, you are missing SIX EndIf statements..

Glenn


MrYretix
(Lurker)
2007-04-16 02:39 PM
Re: AddPrinter Problem

Okey, what must I do then?
Where must I set SIX EndIf statements ??




Mart
(KiX Supporter)
2007-04-16 03:05 PM
Re: AddPrinter Problem

We have two groups for each printer. One is for the users that should get the printer as default and one for the users that should get the printer as a extra printer. On each group we do an if - else - endif.

Something like this.

 Code:
;printer1
If InGroup("printer1-defgrp")
	AddPrinterConnection ("\\server\printer1") = 0
	SetDefaultPrinter ("\\server\printer1")
EndIf
If InGroup("printer1-extgrp")
	AddPrinterConnection ("\\server\printer1") = 0
EndIf
;
;printer2
If InGroup("printer2-defgrp")
	AddPrinterConnection ("\\server\printer2") = 0
	SetDefaultPrinter ("\\server\printer2")
EndIf

If InGroup("printer2-extgrp")
	AddPrinterConnection ("\\server\printer2") = 0
EndIf


The scripts get written automatically by and admin script that runs every two hours and checks the group membership of all users. First we collect all users from AD and then we use the UserGroups UDF to get the group membership for each user.
UserGroups() - returns all groups of a given user


Glenn BarnasAdministrator
(KiX Supporter)
2007-04-16 05:13 PM
Re: AddPrinter Problem

You need to match each IF with an ENDIF - the simplest way is via indents (as you do) AND adding a comment to the EndIf so you know "who it belongs to".
 Code:
IF InOU("FirstOU")
  Do this, and that, and some other things..
ENDIF ; in "FirstOU"


I do this with long blocks of IF/Else/Endif, but if you aren't used to it, or are debugging, it makes sense to add the comments to EVERY If/EndIf pair.

Don't forget, "InOU" is not a Kix function - if you want to check OU membership, you need to write or download a UDF and include it in your code.

Glenn


Witto
(MM club member)
2007-04-16 07:12 PM
Re: AddPrinter Problem

InOU()
Sounds a bit like InContainer() - Determines if the current account or computer is in a container


Glenn BarnasAdministrator
(KiX Supporter)
2007-04-16 08:22 PM
Re: AddPrinter Problem

Don't think I posted this (yet)- this could also work - right from the example in the header.

Glenn


;; 
;;====================================================================== 
;; 
;;FUNCTION       GetUserOU() 
;; 
;;ACTION         Returns the OU string for the current user 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION	 1.0 - 2006/12/06 
;; 
;;SYNTAX         GetUserOU(Object) 
;; 
;;PARAMETERS     Object - OPTIONAL - Specify a particular object ID to return 
;; 
;;REMARKS        Initial development for use in the Universal Login Script 
;; 
;;RETURNS        String - comma-delimited OU list - OU=x,OU=y,DC=dom,DC=local 
;;               or, with Object specified, the specific object without the qualifier 
;;               eg: GetUserOU(1) returns "y" instead of "OU=x,OU=y,DC=dom,DC=local" 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       If GetUserOU(1) = "My Dept OU"  
;;                 Use E: \\server\share 
;;               EndIF 
; 
Function GetUserOU(OPTIONAL $_Object)
 
  Dim $_aTemp, $_Work, $_ADSys, $_First, $_I, $_D
 
  $_D = ''
 
  $_ADSys = CreateObject('ADSystemInfo')
  If @ERROR Exit @ERROR EndIf			; exit if error creating object 
  $_aTemp = $_ADSys.UserName
  If @ERROR Exit @ERROR EndIf			; exit if error obtaining data 
 
  ; Handle a "Last, First" situation 
  $_I = InStr($_aTemp, '\,')
  If $_I
    $_aTemp = Left($_aTemp, $_I - 1) + SubStr($_aTemp, $_I + 2)
  EndIf
 
  ; Remove the CN= portion 
  If InStr($_aTemp, 'CN=')
    $_aTemp = SubStr($_aTemp, InStr($_aTemp, ',') + 1)
  EndIf
 
  ; Split the remaining OU and DC components into an array 
  $_aTemp = Split($_aTemp, ',')
 
  ; Return only OU and DC info - build the string 
  For Each $_I in $_aTemp
    If Not InStr($_I, 'CN=')
      $_Work = $_Work + $_D + $_I
      $_D = ','
    EndIf
  Next
 
  ; return the string, or the specific object requested 
  $GetUserOU = IIf($_Object, SubStr(Split($_Work, ',')[$_Object], 4), $_Work)
 
  Exit 0
 
EndFunction
 
 
 


Witto
(MM club member)
2007-04-17 12:26 AM
Re: AddPrinter Problem

Maybe it is this one?
InOU() - Check user/computer OU from Active Directory