Page 5 of 5 <12345
Topic Options
#202491 - 2011-06-22 12:03 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: Mart
See my post just above yours. The Next should be replaced by Loop.

You need to put the code inside the code that checks if the person is on a xen server or not.


that must be inside the loop?

;for non xen clients
$computerprt = left (@wksta, 6)
Select
case $computerprt = "LA-DOC"
;Connect LA-DOC printers.
EndSelect

Top
#202492 - 2011-06-22 05:01 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yes, it should be inside the loop.

Something like this (untested):
 Code:
$ComputerPrt = Left(@wksta, 6)
If $ComputerPrt = "VA-CTX"
	$index = 0
	$keyname = EnumKey("HKLM\software\citrix\PortICA\uxpersistence\", $index)
	While @ERROR = 0
		Select
			Case InStr($keyname, "LA-DOC")
				$client = Left($keyname, 6)
			Case InStr($keyname, "LA-ROO")
				$client = Left($keyname, 6)
			Case InStr($keyname, "aaaaaa")
				$client = Left($keyname, 6)
		EndSelect
		$Index = $Index + 1
		$keyname = EnumKey("HKLM\software\citrix\PortICA\uxpersistence\", $index)
	Loop
	Select
		Case $client = "LA-ROO"
			$rc = AddPrinterConnection("\\VA-PRN-001\printer1")
			$rc = SetDefaultPrinter("\\VA-PRN-001\printer1")
		Case $client = "LA-DOC"
			$rc = AddPrinterConnection("\\VA-PRN-001\printer1")
			$rc = AddPrinterConnection("\\VA-PRN-001\printer2")
			$rc = SetDefaultPrinter("\\VA-PRN-001\printer1")
	EndSelect
Else
	;Not on a xen server.
	;Do stuff for non xen sessions here.
EndIf


Some things can be combined but in the example above I kept all steps separated to make it more readable.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202565 - 2011-07-05 11:25 AM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
hi, this works good.
but the big test will be when all users are back from vacation (over 6 weeks)

also like to integrate BGinfo in this script and delete old printer connections. anyone knows a best way to do this?

thanks, thanks, thanks

Top
#202577 - 2011-07-06 09:19 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
There are several way to delete old printers.
What we do for example is enumerate all installed network printers and store it in a temp file, install all needed printers and store the names of the needed printers in the same temp file, at the end of the script read both values from the temp file, compare the "old" printer to the "new" printers and delete whatever is in the list of "old" printers and not in the list of "new" printers. See below for an example.

The example below requires some UDF's.
ArrayEnumKey() - Creates an array of names of the subkeys contained in a registry key
PriMapState() - Checks for existent printer connection
ArrayComp() - Compares two 1 Dimensional Arrays

 Code:
Break on

$printerlog = "c:\somefolder\printers.ini"


;Region Get all installed network printers.
;Set the key that should be enumerated.
$key = "HKCU\Printers\Connections"
;Enumerate network printers key.
$oldprinters = ArrayEnumKey($key)
;Do stuff for each value
For Each $value in $oldprinters
	;Split the value on the comma.
	$value = Split($value, ",")
	;Put the value back together so that is represents the correct path to the printer.
	$value1 = "\\" + $value[2] + "\" + $value[3]
	;Add the created value to a variable to be written to the printer log file.
	$oldprinter = $oldprinter + "~" + $value1
Next
;Write all old printers to the printer log file.
$rc = WriteProfileString($printerlog, "Printers", "OldPrinters", $oldprinter)
;endregion

;Region Add printers
;Map printer printer01
;Set printer name.
$printer = "\\Server01\printer01"
;Check group membership.
If InGroup("SomeGroup01")
	;Check if the printer is already installed.
	If Not PriMapState($printer)
		;Printer is not installed. Add printer.		
		$rc = AddPrinterConnection($printer)
	EndIf
	;Read all so far installed printers from the printer log file.
	$connected = ReadProfileString($printerlog, "Printers", "NewPrinters")
	;Add the printer name to a variable to be written to the printer log file.
	$connected = $connected + "~" + $printer
	;Write the new printers value to the printers log file.
	$rc = WriteProfileString($printerlog, "Printers", "NewPrinters", $connected)
EndIf

;Set printer name.
;Map printer printer02
$printer = "\\Server01\printer02"
;Check group membership.
If InGroup("SomeGroup02")
	;Check if the printer is already installed.
	If Not PriMapState($printer)
		;Printer is not installed. Add printer.		
		$rc = AddPrinterConnection($printer)
	EndIf
	;Read all so far installed printers from the printer log file.
	$connected = ReadProfileString($printerlog, "Printers", "NewPrinters")
	;Add the printer name to a variable to be written to the printer log file.
	$connected = $connected + "~" + $printer
	;Write the new printers value to the printers log file.
	$rc = WriteProfileString($printerlog, "Printers", "NewPrinters", $connected)
EndIf
;endregion

;Region Delete unneeded printers
;Read all old network printers from the printer log file.
$oldprinters = ReadProfileString($printerlog, "Printers", "OldPrinters")
;Check if there are any old printers in the list.
If $oldprinters <> ""
	;Split the old printers on the ~ character
	$oldprinters = Split($oldprinters, "~")
EndIf
;Check each element of the array.
For $i = 0 to UBound($oldprinters)
	;Remove extra ~ characters.
	$oldprinters[$i] = Join(Split($oldprinters[$i], "~"), "")
Next

;Read all new printers from the printer log file.
$newprinters = ReadProfileString($printerlog, "Printers", "NewPrinters")
;Check if there are any new printers in the list.
If $newprinters <> ""
	;Split the new printers on the ~ character
	$newprinters = Split($newprinters, "~")
EndIf
;Check each element of the array.
For $i = 0 to UBound($newprinters)
	;Remove extra ~ characters.
	$newprinters[$i] = Join(Split($newprinters[$i], "~"), "")
Next

;Compare the list of old and new printers.
$tobedeletedprinters = ArrayComp($newprinters, $oldprinters)
;Check if there are any printers that should be deleted.
If UBound($tobedeletedprinters) > -1
	For Each $tobedeletedprinter in $tobedeletedprinters
		;Delete each printer that should be deleted.
		$rc = DelPrinterConnection($tobedeletedprinter)
	Next
EndIf
;endregion


Adding BGInfo is easy. BGInfo has lots of command line parameters and can be scripted. You should create a config file first by starting BGInfo, adding the stuff you want to display and save the config file. If you start BGInfo.exe /? from a command windows you get an overview of all command line parameters.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 5 of 5 <12345


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

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

Generated in 0.269 seconds in which 0.243 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