Page 1 of 1 1
Topic Options
#124820 - 2004-08-12 05:02 PM Installing network printers using kix
HelpMe Offline
Fresh Scripter

Registered: 2004-08-11
Posts: 16
Hi all ! I've got a question... I'd like to install printers on my client using Kix. No matter with this it works. The problem is that i would like to use the command "If Ingroup" using the computer name and not the user name. Is it possible ? I tried this :

If @WKSTA Ingroup ("abc")
AddPrinterConnection ("\\server\printer name 1")
EndIf

If @WKSTA Ingroup ("def")
AddPrinterConnection ("\\server\printer name 2")
EndIf

The problem is that he just install all of the printer instead of checking in which group is the computer name.

Can someone help me ? Thanks !!!

Top
#124821 - 2004-08-12 05:09 PM Re: Installing network printers using kix
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
INGROUP() only works for users afaik. The syntax is also wrong.
http://www.scriptlogic.com/kixtart/htmlhelp/default.asp

If this is an active directory domain, you could for example check which OU the computer is in, and map printers that way.


Edited by masken (2004-08-12 05:11 PM)
_________________________
The tart is out there

Top
#124822 - 2004-08-12 05:17 PM Re: Installing network printers using kix
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This has been discussed often and there are UDFs that will do it for you. Seek and ye shall find.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124823 - 2004-08-13 02:55 PM Re: Installing network printers using kix
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Moderator's note: A new thread was started on the same topic.
Still can't add network printer...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124824 - 2004-12-02 09:09 PM Re: Installing network printers using kix
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
With much help from members of this board, I have a script that works for me.

Code:

;kixtart.kix - primary login script
;Setup Printers for computers in Printers Group
if ComputerInGroup('Printer Setup Group')=1
call @ScriptDir+'\printers.kix'
endif

;============ ComputerInGroup Function ===========
;Function ComputerInGroup()
;
;Author Radimus (really Howard Bullock's code)
;
;Contributors Almost entirely written by Howard Bullock
; I just stuffed it into UDF format and posted it
;
;Action Returns a 1 if the @wksta is a member of domain group
;
;Syntax ComputerInGroup($group,optional $Domain)
;
;Version 1.00
;
;Date 2003-Sep-03
;
;Date Revised
;
;Revision Reason 1.00
;
;Parameters $group = name of group to test for
; $domain = optional parameter for testing a different domain than current
;
;Remarks see Ingroup(), but for computer accounts instead of user accounts
;
;Returns 1 if in specified group
; 0 if not
; @error =1 for bad group or domain
;
;Dependencies ADSI
;
;KiXtart Ver Written and tested with KiXtart v4.21
;
;Example If ComputerInGroup('domain computers')=1
; ? 'Computer is a member'
; endif

Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction




Code:

;printers.kix called by kixtart.kix for computers in Printers Group

$WS = GetObject('WinNT://' + @domain + '/' + @wksta + '$$')

if @error
? @serror
else

$ps1='server1'

for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add additional printers ---

if left($GrpName,4) = 'A01_'
$addlprinter = substr($GrpName,5)
$addlprinter = $ps1+'\'+$addlprinter
$addlprinter = '\\'+$addlprinter
? "Additional Printer: "$addlprinter

if not PriMapState($addlprinter)
? "Status: Printer not connected " + $addlprinter
$nul=AddPrinterConnection($addlprinter)
? "Status: Printer added " + $addlprinter
? @serror ?
endif
endif

;--- Add and set default printer ---

if left($GrpName,4) = 'D01_'
$defprinter = substr($GrpName,5)
$defprinter = $ps1+'\'+$defprinter
$defprinter = '\\' + $defprinter
? "** Printers assigned through Printer Setup Group **"
? " "
? "Default Printer: "$defprinter

if not PriMapState($defprinter)
? "Status: Printer not connected "+$defprinter
$nul=AddPrinterConnection($defprinter)
? "Status: Printer added "+ $defprinter
? @serror ?
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer set "+ $defprinter
? @serror ?
endif

if PriMapState($defprinter)<>2
$nul=SetDefaultPrinter($defprinter)
? "Status: Default Printer changed " + $defprinter
? @serror ?
?
endif
endif
next
endif

;FUNCTION PriMapState v1.1
;
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;
;ACTION Checks for existent networkprinter connection
;
;SYNTAX PriMapState(PRINTER)
;
;PARAMETERS PRINTER
; Printers name to be checked
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;
;REMARKS code for w9x adapted from BrianTX
;
;DEPENDENCIES none
;
;EXAMPLE if not PriMapState('\\server\printer1')
; "printer not connected!"
; endif
;
;CODE
function PriMapState($_Pri)
if @inwin=1
if len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
; if instr(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),$_Pri)
if split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri
$PriMapState=2
else
$PriMapState=1
endif
endif
else
dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
for $_C=0 to 259
$_C2=enumkey($_Root,$_C)
If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
$PriMapState = 2
Else
$PriMapState = 1
Endif
Endif
if $_C2=259 $_C=$_C2 endif
next
endif
endfunction




Top
#124825 - 2004-12-02 09:16 PM Re: Installing network printers using kix
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
All of my printers are named similarly, q-printer. I created group names based on printer name. 2 groups exist for each printer. D01_q-printer A01_q-printer. I created an AD group and put the COMPUTERS in the group. I use ComputerInGroup.udf to see if the computer is a member and then add printers and set as default based on printer group name. I have many printers, so it was well worth the amount of time to figure out this script. And not everyone gets printers assigned by a script. So first I put the computers in the Printer Setup Group, and if they are here, I call the printers.kix. Printers.kix looks at the groups created for each printer. If you don't have many printers and all users run the script, you can use a simpler script.

Create an AD Group for each printer.

Code:

If ComputerInGroup("abc")
AddPrinterConnection ("\\server\printer name 1")
EndIf

If ComputerInGroup("def")
AddPrinterConnection ("\\server\printer name 2")
EndIf

;============ ComputerInGroup Function ===========
;Function ComputerInGroup()
;
;Author Radimus (really Howard Bullock's code)
;
;Contributors Almost entirely written by Howard Bullock
; I just stuffed it into UDF format and posted it
;
;Action Returns a 1 if the @wksta is a member of domain group
;
;Syntax ComputerInGroup($group,optional $Domain)
;
;Version 1.00
;
;Date 2003-Sep-03
;
;Date Revised
;
;Revision Reason 1.00
;
;Parameters $group = name of group to test for
; $domain = optional parameter for testing a different domain than current
;
;Remarks see Ingroup(), but for computer accounts instead of user accounts
;
;Returns 1 if in specified group
; 0 if not
; @error =1 for bad group or domain
;
;Dependencies ADSI
;
;KiXtart Ver Written and tested with KiXtart v4.21
;
;Example If ComputerInGroup('domain computers')=1
; ? 'Computer is a member'
; endif

Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction


Top
Page 1 of 1 1


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

Who's Online
0 registered and 194 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.074 seconds in which 0.044 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