Hi.

I hope this is the place for this query...

I'm fairly new at KiXTart (have done quite a lot of other programming, though) and have inherited a script that maps network printers in our Citrix TS environment. It works fine, but now we have to make changes to our printer environment. We're moving printers from one server to three, based on driver, which kinda changes things.

Printer names are kept. I have a security group in my AD for each printer, printer name contained within the group name and user indirectly member of it - which is my current method of distribution.

The scope of this excercise is 600 users, 250 printers in 200 geographical locations.

On monday (yep - 5 days) I will have to have the following in working order and I hoped one of you unequalled gurus could give me a few pointers. The main goal is to remove the old printers and replace them with the new without the user noticing.

1. I (think I) need to obtain and keep (for the duration of the script) a list of the user's printers, making a note of which one is the default - and then remove (disconnect) them.

2. I need to ascertain which of my three new printservers the printers I found in bullet one is located on (without trying to add printer and wait for it to fail...). I know that I can query AD for published printers using VBScript - is that possible in KiX? Can I fire a VBScript and pass the list back to KiX?

We run KiXTart v. 4.6, Citrix PS 4.5 on Windows Server 2003, our AD is running in 2003 native mode.

In the following script the domain is called SD, a typical printer group PRT_NOA_OSI_HC and the corresponding printer object NOA_OSI_HC:

 Code:
$Index = 0
$PrintGroups = ""
$PrintName = ""
$HQServer = "\\NOPRTHQ02\"
$HCServer = "\\NOPRTHC02\"
$Server = ""
$Index = 0
$Index2 = 0
$ValueName = ""
$ValueName2 = ""
$Install = "YES"

;====================================
;	REMOVE PRINTERS NOT REGISTERED
;====================================

$Index = 0
:Loop1
$ValueName = ENUMVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", $Index)
If @ERROR = 0
	$ValueName2 = Right ($ValueName, Len ($ValueName) - InStrRev($ValueName, "\"))
	If NOT InGroup ("SD\PRT_" + $ValueName2)
; 		Kommentert ut For NFRA pilot
; 		DelPrinterConnection($ValueName)
; 		? "Printer deleted: " + $ValueName
	EndIf
    $Index = $Index + 1
    Goto Loop1
EndIf

;====================================
;	ADD PRINTERS NOT ALREADY ADDED
;====================================

$Index = 0
Do
	$Group = EnumGroup($Index)
	If Mid($Group,4,4) = "PRT_"
		$PrintGroups = $PrintGroups + ", " + $Group
		$PrintName = Right($Group, Len($Group)-7)
		if Mid($PrintName,4,1) = "_"
			$Server = $HCServer
		else
			$Server = $HQServer
		EndIf
		;   Check Registry - finn alle installerte skriverobjekter
		$Index2 = 0
		:Loop2
		$ValueName = ENUMVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", $Index2)
		If @ERROR = 0
			$ValueName2 = Right ($ValueName, Len ($ValueName) - InStrRev($ValueName, "\"))
			If $ValueName2 = $PrintName
				? "Printer already exist: " + $PrintName
				$Install = "NO"
			EndIf
		    $Index2 = $Index2 + 1
		    Goto Loop2
		EndIf
		If $Install = "YES"
			ADDPRINTERCONNECTION($Server + $PrintName)
			? "Printer added: " + $Server + $PrintName
		EndIf
		$Install = "YES"
	EndIf
	$Index = $Index + 1
Until Len($Group) = 0


;---------------;
; function: MID ;
;---------------;

Function MID($midstring,$midstart,optional $midend)
;SYNTAX mid($midstring,$midstart,optional $midend)
;
;PARAMETERS $Midstring         - String of characters to search
;           $Midstart          - Character Index number to start with.  
;                                Base 1 or -1:  Positve Number = Left, Negative Number = Right
;           $Midend (optional) - Number of Characters to include from $midstart
;
;
;Example
;
;  $string='Hello this is a test'
;
;?  Mid($string,7,4)   ;returns 'this'
;?  Mid($string,7)     ;returns 'this is a test'
;?  Mid($string,-6)    ;returns 'Hello this is a'
;?  Mid($string,-8,2)  ;returns 'is'

  If $midend<0
    $midend=abs($midend)
  Else 
    If $midend>Len($midstring)-abs($Midstart) OR $midend=""
      $midend=0
    EndIf
  EndIf
  Select
    Case $midstart<0
      $midstart=abs($midstart)
      If $midend=0 
        $mid=Left(Right($midstring,Len($midstring)),(Len($midstring)-$midstart)+1)
      Else
        $mid=Left(Right($midstring,($midstart+$midend)-1),$midend)
      EndIf
    Case $midstart>0
      If $midend=0
        $mid= Right(Left($midstring,Len($midstring)),(Len($midstring)-$midstart)+1)
      Else
        $mid=Right(Left($midstring,($midstart+$midend)-1),$midend)
      EndIf
  EndSelect
EndFunction


Help?
_________________________
Share and enjoy - Kjetil