Page 1 of 1 1
Topic Options
#175411 - 2007-04-16 12:25 PM AddPrinter Problem
MrYretix Offline
Lurker

Registered: 2007-03-13
Posts: 2
Loc: Utrecht, The Netherlands
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!



Edited by MrYretix (2007-04-16 12:26 PM)
_________________________
Nice !!!!

Top
#175412 - 2007-04-16 01:44 PM Re: AddPrinter Problem [Re: MrYretix]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#175413 - 2007-04-16 02:39 PM Re: AddPrinter Problem [Re: Glenn Barnas]
MrYretix Offline
Lurker

Registered: 2007-03-13
Posts: 2
Loc: Utrecht, The Netherlands
Okey, what must I do then?
Where must I set SIX EndIf statements ??




Edited by MrYretix (2007-04-16 02:40 PM)
_________________________
Nice !!!!

Top
#175414 - 2007-04-16 03:05 PM Re: AddPrinter Problem [Re: MrYretix]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175418 - 2007-04-16 05:13 PM Re: AddPrinter Problem [Re: MrYretix]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#175424 - 2007-04-16 07:12 PM Re: AddPrinter Problem [Re: Glenn Barnas]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
InOU()
Sounds a bit like InContainer() - Determines if the current account or computer is in a container

Top
#175426 - 2007-04-16 08:22 PM Re: AddPrinter Problem [Re: Witto]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
 
 
 
_________________________
Actually I am a Rocket Scientist! \:D

Top
#175429 - 2007-04-17 12:26 AM Re: AddPrinter Problem [Re: Glenn Barnas]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe it is this one?
InOU() - Check user/computer OU from Active Directory

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.062 seconds in which 0.026 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