Page 1 of 5 12345>
Topic Options
#202340 - 11/05/26 10:56 AM how to read a custom environment variable (XDClientName)
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
old situation:
printers are installed with a kix loginscript based on client computername.
 Code:
$computerprt = left (@wksta, 6)
select 
;Locatie 1
	case $computerprt = "LA-MAN"
		AddPrinterConnection ("\\printserver\printer1")
		SetDefaultPrinter("\\printserver\printer1")
;Locatie 2
	case $computerprt = "CA-DOC"
		AddPrinterConnection ("\\printserver\printer2")
		SetDefaultPrinter("\\printserver\printer2")
endselect


this works and i'm very happy with it.

But we are migrating some clients to XenDesktop 4(locked down), all these virtual clients have the same first 6 characters, only the number is different.
So my kix script isn't working anymore.

I found a little tool on the citrix website: http://support.citrix.com/article/CTX124963
this retrieves the original machines client name and puts them in the windows environment variable.

Now my question is how to let kix read this variable and use this to install the printers?(example above)

I hope my you can understand my question.(it's a bit messy)

thanks


Edited by Mart (11/05/26 02:32 PM)
Edit Reason: Please use code tags when posting code.

Top
#202341 - 11/05/26 11:40 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
Loc: Maryland, USA
Why not just add another select at the begging? Such as:

 Code:
$computerprt = left (@wksta, 6)
select
;Xen systems
case left(@wksta, 6) = "xendes"
AddPrinterConnection ("\\printserver\printerxen")
SetDefaultPrinter("\\printserver\printerxen")
;Locatie 1
case $computerprt = "LA-MAN"
AddPrinterConnection ("\\printserver\printer1")
SetDefaultPrinter("\\printserver\printer1")
;Locatie 2
case $computerprt = "CA-DOC"
AddPrinterConnection ("\\printserver\printer2")
SetDefaultPrinter("\\printserver\printer2")
endselect

Top
#202342 - 11/05/26 12:22 PM Re: how to read a custom environment variable (XDClientName) [Re: BradV]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
no that doesn't work.

some more info:
we have six locations and each location has it's own computernames
Example:
location 1 has computernames that begin with LA-MAN-XXX
Location 2 has computernames that begin with CA-MAN-XXX
so i can deploy printers to specific computers.

whitin citrix all computers (for all locations) have the same name(except the number)

Top
#202343 - 11/05/26 12:33 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
Loc: Maryland, USA
Sorry, I miss-understood. I thought all of your xen systems were at one location.

 Code:
$Y = "And this is how you access environment variables: %USERNAME%..."
So,
 Code:
$computerprt = "%XDClientName%"

Top
#202344 - 11/05/26 01:12 PM Re: how to read a custom environment variable (XDClientName) [Re: BradV]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
Thank you.

don't know what this mean: $Y = "And this is how you access environment variables: %USERNAME%..."

so i use this?
 Code:
$computerprt = "%XDClientName%"
$computerprt = Left(@wksta, 6)
Select
		;Xen systems
	Case Left(@wksta, 6) = "xendes"
		AddPrinterConnection("\\printserver\printerxen")
		SetDefaultPrinter("\\printserver\printerxen")
		;Locatie 1
	Case $computerprt = "LA-MAN"
		AddPrinterConnection("\\printserver\printer1")
		SetDefaultPrinter("\\printserver\printer1")
		;Locatie 2
	Case $computerprt = "CA-DOC"
		AddPrinterConnection("\\printserver\printer2")
		SetDefaultPrinter("\\printserver\printer2")
EndSelect


Edited by Mart (11/05/26 02:34 PM)
Edit Reason: Please use code tags when posting code.

Top
#202345 - 11/05/26 02:13 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
Loc: Maryland, USA
Sorry, I was just trying to subtle about saying, "Read the manual." \:\)

That is a direct quote from the manual about how to read an environment variable.

I think you will have to first determine if the system is a virtual one or not. So,

 Code:
if xen = true
   $computerprt = "%XDClientName%"
else
   $computerprt = left (@wksta, 6)
endif


The way you have it, the variable will be overwritten even if it is a xen computer.

Top
#202346 - 11/05/26 02:28 PM Re: how to read a custom environment variable (XDClientName) [Re: BradV]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
ok thank you so much \:\)

i know i'm not good at it ;\)

where is the "xen" from if xen = true?

when i put all the code together is this correct?
 Code:
If xen = true
	$computerprt = "%XDClientName%"
Else
	$computerprt = Left(@wksta, 6)
EndIf

Select
		;Location 1
	Case $computerprt = "LA-MAN"
		AddPrinterConnection("\\printserver\printer1")
		SetDefaultPrinter("\\printserver\printer1")
		
		;Locatie 2
	Case $computerprt = "CA-DOC"
		AddPrinterConnection("\\printserver\printer2")
		SetDefaultPrinter("\\printserver\printer2")
EndSelect


Edited by Mart (11/05/26 02:36 PM)
Edit Reason: Please use code tags when posting code.

Top
#202347 - 11/05/26 02:40 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 02/03/27
Posts: 4612
Loc: The Netherlands
I think it should be $xen. It should be filled by some code in your script before trying to use it.

I use the SessionType() UDF for this. Check: UDF Library SessionType() - Gets the session type for the current user
This UDF will check if you are on RDP, ICA (Citrix) or a console session.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202348 - 11/05/26 02:46 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4211
Loc: New Jersey
The first question is - are you running "xd4ClientName.exe" before you run the Kix login script? This might be one of those situations where you need to call the login script as a Batch file - the bat file would contain something like
 Code:
@Echo Off
Rem - set the XDCLIENTNAME environment var
XD4ClientName.exe
Rem - Run the Kix login script
kix32.exe kixtart.kix
This will insure that the environment var is defined and present when Kix runs. If you run the XD4ClientName.exe from within Kix, it will set the value in the child shell, which will then die when the command ends.

Running the command on a non-Xen system causes a 4-second delay before the app dies and does NOT set the variable. Thus, if this small delay is acceptable, you could modify your Kix script like this using the above bat file:
 Code:
; Get the computer name - either remote client or local PC as appropriate
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
; Trim to firtst six chars
$ComputerPrt = Left($ComputerPrt, 6)
The rest of your code remains the same. The process I have illustrated is done in 2 steps because IIF is picky about what you place in the args. It's also easier to follow the logic. Basically, if the environment var isn't empty, use that value for the computer name, otherwise get the name from the @WKSTA macro. Trim it to the first 6 chars and process as usual.

If the delay isn't acceptable (and it's better practice anyway), modify the batch file that launches the login script to detect if this is a Xen session and run the XD4ClientName.exe command only when on a Xen server. No changes to the Kix script are necessary since the environment var won't be set either way. I'm not in the office so I can't test the Xen server detection part.. someone else here may be able to help before I can test it further.

Glenn
_________________________

Actually I am a Rocket Scientist! \:D

Top
#202349 - 11/05/26 03:31 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
wow! that's a lot of information. my brain are getting overheated.

my appologies i'm so stupid.

As i'm said i have multiple locations. all location has it's own computernames.
All computernames has 10 charaters:
xx-yyy-zzz
xx = location example LA and CA
yyy = department example FAC (factory) and OFF (office)
zzz = the number of the computer example 001

On all locations some computers are locked-down and they logged in with a citrix virtualdesktop. All these virtual desktops has the computername: VA-CTX-001 (which the number varies)

Example: on location LA there are 2 users in an office and 1 printer.
One user has a regular desktop and logs on this desktop and the other user logs is with citrix. both user must get the same printer.

In the existing situation the logon script is defined in the ActiveDirectory. This logon script is a batch file which start the kix script:
 Code:
 
@Echo Off
net use P: \\server\App$
kix32.exe Printers.kix


and my originally kix script:
 Code:
$computerprt = left (@wksta, 6)

select 

	case $computerprt = "LA-FAC"
		AddPrinterConnection ("\\printserver\printer1")
		SetDefaultPrinter("\\printserver\printer1")

	case $computerprt = "LA-OFF"
		AddPrinterConnection ("\\printserver\printer2")
		SetDefaultPrinter("\\printserver\printer2")

	case $computerprt = "CA-REC"
		AddPrinterConnection ("\\printserver\printer3")
		SetDefaultPrinter("\\printserver\printer3")

	case $computerprt = "CA-ROO"
		AddPrinterConnection ("\\printserver\printer4")
		AddPrinterConnection ("\\printserver\printer1")
		SetDefaultPrinter("\\printserver\printer4")

endselect
 


Can someone make it complete? I would buy you a beer or so, but i'm from the netherlands, so i also can do a paypal deposit if needed ;\)

Top
#202351 - 11/05/26 03:59 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4211
Loc: New Jersey
Simple..

1. Copy the XD4ClientName.exe to your NetLogon folder
2. Add the XD4ClientName.exe command to your existing batch file, immediately after the existing "Net Use" command.
3. Replace the current line "$computerprt = left (@wksta, 6)" in your kix script with the following 2 lines:
 Code:
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = Left($ComputerPrt, 6)
4. Test!

As I said, this will result in an approximate 4 second delay on non Xen systems. If you can identify the Xen computer from within the BATCH file, you could do something like this in your batch file instead..
 Code:
If %COMPUTERNAME%==xenserver   XD4ClientName.exe
so it only runs when connecting to a Xen server. Try the 4 steps above first to see how it works, then figure out how to identify the Xen server(s) in the batch file and run the XD4ClientName command only when on a Xen system.

Glenn




Edited by Glenn Barnas (11/05/27 01:05 PM)
Edit Reason: chars were missing
_________________________

Actually I am a Rocket Scientist! \:D

Top
#202354 - 11/05/26 07:24 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 02/11/29
Posts: 1992
Loc: Tulsa, OK
Maybe Im looking at this wrong, but should this...

$ComputerPr = IIf(%XDClientName%,%XDCLientName,@WKSTA)

be this...

$ComputerPr = IIf(%XDClientName%,%XDCLientName%,@WKSTA)

?

Top
#202355 - 11/05/27 09:17 AM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
i'm confused now.

$ComputerPr = IIf(%XDClientName%,%XDCLientName,@WKSTA)
$ComputerPr = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = IIf(%XDClientName%,%XDCLientName,@WKSTA)
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)

which?

Top
#202356 - 11/05/27 09:22 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 02/03/27
Posts: 4612
Loc: The Netherlands
Use the one Shane suggested. Environment variables always start and end with a percentage character. Glenn made a small typo.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202357 - 11/05/27 09:47 AM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
First.Thank you all for your answers and great help \:\)

it's:
 Code:
$computerprt = IIf(%XDClientName%,%XDClientName%,@WKSTA)
$computerprt = Left($computerprt, 6)
 


i've test it, but it doesn't work. no printers.
the XDClientName.exe works,because the variable is written.
when i launch \\server\netlogon\kix32.exe logonscript.kix from start - run
then the printers are loaded.

how to solve this?

any idea?

Top
#202358 - 11/05/27 10:27 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 02/03/27
Posts: 4612
Loc: The Netherlands
The code below is an example. It only has two locations but this can obviously be expanded.

It checks if the user is in an ICA session, if yes it should run XD4ClientName.exe and translate %XDClientName% variable into a kix style variable. It check the first two characters of the client name and can run whatever is needed when a case statements is true. It requires the SessionType UDF I linked to earlier.

 Code:
Break on

$sessiontype = SessionType()

If $sessiontype = "ICA"
	;Run XD4ClientName.exe here.
	$clientname = ExpandEnvironmentVars(%XDClientName%)
	Select
		Case Left($clientname, 2) = "LA"
			;Do LA stuff
		Case Left($clientname, 2) = "CA"
			;Do CA stuff
	EndSelect
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202359 - 11/05/27 11:24 AM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
now i'm lost \:\(
Top
#202360 - 11/05/27 11:47 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
Loc: Maryland, USA
Where are you lost? My previous post told you that you can't set a variable on one line and then re-set it on the next and expect it to have two different values. Go back to what Glenn said and use Mart's suggestion to fill in the "xen = true" part. That was just pseudo code.

So, have a batch file launch it. Run the XD4ClientName application in the batch file and then call your kix script. In your kix script, use the SessionType function as Mart suggested to do the "xen = true " test.

So, start with a batch file:
 Code:
@Echo Off
Rem - set the XDCLIENTNAME environment var
XD4ClientName.exe
Rem - Run the Kix login script
kix32.exe kixtart.kix


In your kixtart.kix file:

 Code:
$sessiontype = SessionType()

If $sessiontype = "ICA"
   $computerprt = left ("%XDClientName%", 6)
else
   $computerprt = left (@wksta, 6)
endif

select 
   case $computerprt = "LA-FAC"
      AddPrinterConnection ("\\printserver\printer1")
      SetDefaultPrinter("\\printserver\printer1")
   case $computerprt = "LA-OFF"
      AddPrinterConnection ("\\printserver\printer2")
      SetDefaultPrinter("\\printserver\printer2")
   case $computerprt = "CA-REC"
      AddPrinterConnection ("\\printserver\printer3")
      SetDefaultPrinter("\\printserver\printer3")
   case $computerprt = "CA-ROO"
      AddPrinterConnection ("\\printserver\printer4")
      AddPrinterConnection ("\\printserver\printer1")
      SetDefaultPrinter("\\printserver\printer4")
endselect


Is that any clearer?

Top
#202361 - 11/05/27 12:15 PM Re: how to read a custom environment variable (XDClientName) [Re: BradV]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
ok, i'm gonna try it right away.

but do i need to load this also: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=195471

and i was wondering where is the "ICA" comes from? from this line: If $sessiontype = "ICA"

Top
#202362 - 11/05/27 01:16 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
arjanv Offline
Fresh Scripter

Registered: 10/03/11
Posts: 49
Loc: netherlands
i've tried this.
 Code:
  
@Echo Off
Rem - set the XDCLIENTNAME environment var
XD4ClientName.exe
Rem - Run the Kix login script
kix32.exe kixtart.kix


 Code:
$sessiontype = SessionType()

If $sessiontype = "ICA"
   $computerprt = left ("%XDClientName%", 6)
else
   $computerprt = left (@wksta, 6)
endif

select 
   case $computerprt = "LA-FAC"
      AddPrinterConnection ("\\printserver\printer1")
      SetDefaultPrinter("\\printserver\printer1")
   case $computerprt = "LA-OFF"
      AddPrinterConnection ("\\printserver\printer2")
      SetDefaultPrinter("\\printserver\printer2")
   case $computerprt = "CA-REC"
      AddPrinterConnection ("\\printserver\printer3")
      SetDefaultPrinter("\\printserver\printer3")
   case $computerprt = "CA-ROO"
      AddPrinterConnection ("\\printserver\printer4")
      AddPrinterConnection ("\\printserver\printer1")
      SetDefaultPrinter("\\printserver\printer4")
endselect


also tried this:

 Code:
Break on

$sessiontype = SessionType()

If $sessiontype = "ICA"
	Run XD4ClientName.exe
	$clientname = ExpandEnvironmentVars(%XDClientName%)

	Select
		Case Left($clientname, 6) = "LA-DOC"
		AddPrinterConnection ("\\VA-PRN-001\LYC - ALG - op1020")
		AddPrinterConnection ("\\VA-PRN-001\LYC - LHB - HP8000")
		AddPrinterConnection ("\\VA-PRN-001\LYC - ROO - HP7700")
		SetDefaultPrinter("\\VA-PRN-001\LYC - ALG - op1020")

	EndSelect
EndIf

Function SessionType()

	Dim $sessionname, $session

	$sessionname = ExpandEnvironmentVars(%sessionname%)
	$session = Left($sessionname, 3)
	Select
		Case $Session = "Con"
			$sessiontype = "Console session"
		Case $session = "RDP"
			$sessiontype = "Remote desktop session"
		Case $session = "ICA"
			$sessiontype = "Citrix ICA session"
		Case 1
			$sessiontype = "Unknown session type"
	EndSelect
EndFunction


none work.

Top
Page 1 of 5 12345>


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (green78) and 144 anonymous users online.
Newest Members
Keris2112, Jorromans, qrstuv140696, Bloodboy, NIJAKIX
17451 Registered Users

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