#202340 - 2011-05-26 10:56 AM
how to read a custom environment variable (XDClientName)
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
old situation: printers are installed with a kix loginscript based on client computername.
$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 (2011-05-26 02:32 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#202341 - 2011-05-26 11:40 AM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Why not just add another select at the begging? Such as:
$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 - 2011-05-26 12:22 PM
Re: how to read a custom environment variable (XDClientName)
[Re: BradV]
|
arjanv
Fresh Scripter
Registered: 2010-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 - 2011-05-26 12:33 PM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Sorry, I miss-understood. I thought all of your xen systems were at one location.
$Y = "And this is how you access environment variables: %USERNAME%..." So, $computerprt = "%XDClientName%"
|
Top
|
|
|
|
#202344 - 2011-05-26 01:12 PM
Re: how to read a custom environment variable (XDClientName)
[Re: BradV]
|
arjanv
Fresh Scripter
Registered: 2010-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?
$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 (2011-05-26 02:34 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#202345 - 2011-05-26 02:13 PM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
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,
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 - 2011-05-26 02:28 PM
Re: how to read a custom environment variable (XDClientName)
[Re: BradV]
|
arjanv
Fresh Scripter
Registered: 2010-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?
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 (2011-05-26 02:36 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#202348 - 2011-05-26 02:46 PM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
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@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:; 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!
|
Top
|
|
|
|
#202349 - 2011-05-26 03:31 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Glenn Barnas]
|
arjanv
Fresh Scripter
Registered: 2010-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:
@Echo Off
net use P: \\server\App$
kix32.exe Printers.kix
and my originally kix script:
$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
|
|
|
|
#202355 - 2011-05-27 09:17 AM
Re: how to read a custom environment variable (XDClientName)
[Re: ShaneEP]
|
arjanv
Fresh Scripter
Registered: 2010-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
|
|
|
|
#202357 - 2011-05-27 09:47 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
First.Thank you all for your answers and great help
it's:
$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
|
|
|
|
#202359 - 2011-05-27 11:24 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
now i'm lost
|
Top
|
|
|
|
#202360 - 2011-05-27 11:47 AM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
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: @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:
$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 - 2011-05-27 12:15 PM
Re: how to read a custom environment variable (XDClientName)
[Re: BradV]
|
arjanv
Fresh Scripter
Registered: 2010-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 - 2011-05-27 01:16 PM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
i've tried this.
@Echo Off
Rem - set the XDCLIENTNAME environment var
XD4ClientName.exe
Rem - Run the Kix login script
kix32.exe kixtart.kix
$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:
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|