Page 1 of 1 1
Topic Options
#212490 - 2017-05-09 02:52 PM Set default printer
cheechchong Offline
Just in Town

Registered: 2017-05-09
Posts: 2
Loc: Germany
Hi,

I´m on my way to migrate our exiting domain to another.
For conneting shares and printers I´d like to us kix.
As connecting to shares and printers works well. but not set them up as default.
I´d like to to set the default printers by group. Is this possible?
Here my scipt snippet:

this workes:
 Code:
IF INGROUP("G_IT")
	ADDPRINTERCONNECTION ("\\"+$PrintServer+"\printer1") = 0
EndIf

this not:
 Code:
IF INGROUP("G_IT")
	SetDefaultPrinter ("\\"+$PrintServer+"\printer1") = 0
Endif


Thanks


Edited by cheechchong (2017-05-09 02:52 PM)

Top
#212491 - 2017-05-09 03:12 PM Re: Set default printer [Re: cheechchong]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Kix uses the share name for some functions and the printer name for others. I didn't like have to remember which was which or name the printers and the share name the same thing. Both are options. The third option is to use the UDF PrinterConnection. Everything is controlled by one function and the share name.

PrinterConnection -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203840#Post203840

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1

Top
#212495 - 2017-05-10 08:35 AM Re: Set default printer [Re: Allen]
cheechchong Offline
Just in Town

Registered: 2017-05-09
Posts: 2
Loc: Germany
Hi,
thanks for your answer. To be honest I`m really new in kix scripting, and i really want to keep it simple.
I´ve read the links but I don´t get it. Maybe some has an example?
Goal is really only: Connect Printer if user is in a specific AD Group, and set this printer as default.
I´ve tried the default with diffrent printernames: Sharename, Windows Printername, Printer discription and even with the port number.
Didn´t work.
Thanks

Top
#212497 - 2017-05-10 11:38 AM Re: Set default printer [Re: cheechchong]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Something simple as this should work. Please keep in mind that the AddPrinterConnection function requires the share name of the printer (something like \\server\printer01) and SetDefaultPrinter requires the name of the printer (HP LaserJet Finance for example).

To avoid issues with adding printers and setting them as default I always keep the printer name and the share name exactly the same. This is not a requirement but it makes things a heck of a lot easier.

 Code:
Break on

If InGroup("AD_groupname")
	$rc = AddPrinterConnection("\\Server\PrinterShareName")
	? @ERROR
	? @SERROR
	$rc = SetDefaultPrinter("Printername")
	? @ERROR
	? @SERROR
Else
	? "User " + @USERID + " is not in the correct AD group"
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#212504 - 2017-05-11 12:20 AM Re: Set default printer [Re: Mart]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I use groups to set printers. There needs to be a naming convention used for this script to work.

All printers have two matching groups

Ex Printer name
q-mis

Ex Group name
A01_q- Print server 1 add'l printer
D01_q- Print server 1 default printer

A02_q- Print server 2 add'l printer
D02_q- Print server 2 default printer

2 groups for this printer on print server 1: A01_q-mis and A01_q-mis
2 groups for this printer on print server 2: A02_q-mis and A02_q-mis


 Code:
********** Beginning of printer mapping *********
call @Scriptdir+'\primapstate.udf'

$WS = GetObject('WinNT://' + @domain + '/' + @wksta + '$$')
 
if @error
   ? @serror
else

$ps1='prn01'        ; site1 ps1
$ps2='prn02'        ; site2 ps2
$ps3='oma-prn01'    ; site3 ps1
$ps4='oma-prn02'    ; site3 ps2
$ps5='pro-prn01'    ; site4


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


;--- Add additional printers ---

     if left($GrpName,2) = 'A0' ;

	$psn = substr($Grpname,2,2)  ;print server number determined by 2-3 character A01=PS1 A02=PS2

	if $psn='01' $ps=$ps1 endif
	if $psn='02' $ps=$ps2 endif
	if $psn='03' $ps=$ps3 endif
	if $psn='04' $ps=$ps4 endif
	if $psn='05' $ps=$ps5 endif

	$addlprinter = substr($GrpName,5)  ;printer group name starts at 5th character
	$addlprinter = $ps+'\'+$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,2) = 'D0'  ;print server number determined by third character D01=PS1 D02=PS2

	$defprinter = substr($GrpName,5) ;printer group name starts at 5th character
	$psn = substr($Grpname,2,2)

	if $psn='01' $ps=$ps1 endif
	if $psn='02' $ps=$ps2 endif
	if $psn='03' $ps=$ps3 endif
	if $psn='04' $ps=$ps4 endif
	if $psn='05' $ps=$ps5 endif


        $defprinter = $ps+'\'+$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




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
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.037 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org