#202440 - 2011-06-08 11:52 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Arend_]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
I know I said I wasn't going to try to help anymore...but I can't help myself. (and I was really wanting to get it up to 4 pages )
Try this code... Again I can't test it completely because I don't have the servers necessary, but I know the .bat testing works, so as long as all of your presentation servers are named with the "xx-ctx-ddcx" convention, and %computername% is available on your servers, and your servers are 64 bit, it should work. (if your servers are not 64 bit, change out XD4ClientName.exe to XDClientName.exe)
BAT FILE
@Echo Off
net use P: \\server\App$
REM Sets tempcomp to chars 8-10 of computername
set tempcomp=%computername:~7,3%
REM If tempcomp is ddc then assumes server and runs
REM the /i is used to make it non case sensitive
if /i "%tempcomp%"=="ddc" (XD4ClientName.exe)
REM Runs the kix script
kix32.exe kixtart.kix KIX SCRIPT
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = Left($ComputerPrt, 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
|
Top
|
|
|
|
#202441 - 2011-06-09 02:38 PM
Re: how to read a custom environment variable (XDClientName)
[Re: ShaneEP]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
thanks all!!
I don't have the time today to test all the options above.
First i've tested it manually. just logged on without script and then started xdclient.exe and then from start run: \\server\netlogon\kix32.exe kixscript.kix this works.......so that's a start.
the examples from above posts i doubt if this can work because i don't think the client will see anything about the presentation servers. so it can't retreive the xen server name...or can it?
i'm going to try to test some more tomorrow.
also i was thinking: when i put a file on the c drive of the virtual machine with for example the name "citrix.txt" can we do a if exist citrix.txt and then load xdclient.exe
or let kix read the virtual computername e.g. va-ctx-*** and the load xdclient.exe (if computername is va-ctx then load xdclient.exe and loads the rest of the script.)
i was thinking out load.
|
Top
|
|
|
|
#202444 - 2011-06-09 04:02 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
just has a couple of minutes spare time.
i've test this, and the xdclient run without error(at least not noticable), and the environment variable is present.
$ComputerPrt = left (@wksta, 6)
select
case $ComputerPrt = "VA-CTX"
run "\\server\netlogon\XDClientName.exe"
endselect
how to load the rest of the script? do i need a other kix script from the above? or can this run whithin the same script. How to combine these two?
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA) $ComputerPrt = Left($ComputerPrt, 6)
select case $ComputerPrt = "LA-ROO" AddPrinterConnection ("\\VA-PRN-001\printer1") SetDefaultPrinter("\\VA-PRN-001\printer1")
case $ComputerPrt = "LA-DOC" AddPrinterConnection ("\\VA-PRN-001\printer1") AddPrinterConnection ("\\VA-PRN-001\printer2") SetDefaultPrinter("\\VA-PRN-001\printer1")
endselect
thanks
Edited by arjanv (2011-06-09 04:02 PM)
|
Top
|
|
|
|
#202446 - 2011-06-10 11:55 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
Hey Mart,
I saw your post yesterday, and i was convinced that this should work.
but i've just tested it, and no printers are added, but the xdclient still works.
ps. this earlier script works, but that gives the xdclient error popup, but in that script the printers are added. $ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA) $ComputerPrt = Left($ComputerPrt, 6)
select case $ComputerPrt = "LA-DOCK" AddPrinterConnection ("\\VA-PRN-001\printer1") SetDefaultPrinter("\\VA-PRN-001\printer1")
thank you so much for your effort.
Edited by arjanv (2011-06-10 12:20 PM)
|
Top
|
|
|
|
#202448 - 2011-06-10 01:16 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
new problem. When running this. $ComputerPrt = Left(@wksta, 6) If $ComputerPrt = "VA-CTX" Run "\\server\netlogon\XDClientName.exe"
the xdclient variable is present, but i've looked all the time at the system properties under advanced - systemvariables. there is it present, but when do a "set" from commandprompt the variable isn't there. when i then run the xdclient manually then it's also available when do the "set" command, and that's why no printers where added. can this cause this xdclient runs too early for windows perhaps.
it's getting funnier every time;)
I found also a registry setting, maybe it's possible to use this. within the virual client the physical computername is visible under: HKLM\software\citrix\PortICA\uxpersistence\LA-DOC-001
|
Top
|
|
|
|
#202449 - 2011-06-10 01:16 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
sorry i was aware of that.
|
Top
|
|
|
|
#202450 - 2011-06-10 02:43 PM
Re: how to read a custom environment variable (XDClientName)
[Re: arjanv]
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
|
new problem. When running this. $ComputerPrt = Left(@wksta, 6) If $ComputerPrt = "VA-CTX" Run "\\server\netlogon\XDClientName.exe"
the xdclient variable is present, but i've looked all the time at the system properties under advanced - systemvariables. there is it present, but when do a "set" from commandprompt the variable isn't there. when i then run the xdclient manually then it's also available when do the "set" command, and that's why no printers where added. can this cause this xdclient runs too early for windows perhaps. ....
I got a small explanation from Glenn about the xdclientname app and it seems it does not run that well from kix. If you start it from a batch file and directly after this start the kix script it should be better.
.... it's getting funnier every time;) ....
Yes, that’s how it goes sometimes. At some time you will start pulling out your hair, wanting to throw the computer out the window and beat up the first person asking you "Is it done yet?" for no reason but just because you can. These things might be great to blow off some steam but they do not help to fix the issue
.... I found also a registry setting, maybe it's possible to use this. within the virual client the physical computername is visible under: HKLM\software\citrix\PortICA\uxpersistence\LA-DOC-001 ....
Great! You could use ReadValue to get this registry value and start connecting printers based on the result. A small example below. It assumes that the registry key is HKLM\software\citrix\PortICA, the value is uxpersistence and its contents is the name of the physical client.
$ComputerPrt = Left(@WKSTA, 6)
If $ComputerPrt = "VA-CTX"
$client = ReadValue("HKLM\software\citrix\PortICA", "uxpersistence")
Select
Case Left($client, 6) = "LA-DOC"
;Connect LA-DOC printers.
Case Left($client, 6) = "LA-ROO"
;Connect LA-ROO printers.
Case Left($client, 6) = "aaaaaa"
;Connect aaaaaa printers.
EndSelect
Else
;Do stuff for non xen sessions.
EndIf
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#202453 - 2011-06-10 10:20 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Glenn Barnas]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Would changing your BAT file to this get rid of the popup error?
@Echo Off
REM net use P: \\server\App$
REM If va-ctx is in computername then runs
if /i "%computername:~0,6%"=="va-ctx" (XD4ClientName.exe)
REM Runs the kix script
kix32.exe kixtart.kix And then just keep this in your kix script...
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = Left($ComputerPrt, 6)
|
Top
|
|
|
|
#202478 - 2011-06-21 10:08 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
new problem. When running this. $ComputerPrt = Left(@wksta, 6) If $ComputerPrt = "VA-CTX" Run "\\server\netlogon\XDClientName.exe"
the xdclient variable is present, but i've looked all the time at the system properties under advanced - systemvariables. there is it present, but when do a "set" from commandprompt the variable isn't there. when i then run the xdclient manually then it's also available when do the "set" command, and that's why no printers where added. can this cause this xdclient runs too early for windows perhaps. ....
I got a small explanation from Glenn about the xdclientname app and it seems it does not run that well from kix. If you start it from a batch file and directly after this start the kix script it should be better. .... it's getting funnier every time;) ....
Yes, that’s how it goes sometimes. At some time you will start pulling out your hair, wanting to throw the computer out the window and beat up the first person asking you "Is it done yet?" for no reason but just because you can. These things might be great to blow off some steam but they do not help to fix the issue .... I found also a registry setting, maybe it's possible to use this. within the virual client the physical computername is visible under: HKLM\software\citrix\PortICA\uxpersistence\LA-DOC-001 ....
Great! You could use ReadValue to get this registry value and start connecting printers based on the result. A small example below. It assumes that the registry key is HKLM\software\citrix\PortICA, the value is uxpersistence and its contents is the name of the physical client.
$ComputerPrt = Left(@WKSTA, 6)
If $ComputerPrt = "VA-CTX"
$client = ReadValue("HKLM\software\citrix\PortICA", "uxpersistence")
Select
Case Left($client, 6) = "LA-DOC"
;Connect LA-DOC printers.
Case Left($client, 6) = "LA-ROO"
;Connect LA-ROO printers.
Case Left($client, 6) = "aaaaaa"
;Connect aaaaaa printers.
EndSelect
Else
;Do stuff for non xen sessions.
EndIf
i've made a screenshot from regedit:
|
Top
|
|
|
|
#202479 - 2011-06-21 10:09 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Glenn Barnas]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
err - yup!
The command to set the environment variable must be run BEFORE the kix script, AND MUST be run in the same environment where it was set. That is..
You must have a batch file that runs the EXE and then runs the Kix script. The bat file runs the EXE that sets the environment var, then runs the kix script. This way, the variable is present in the environment used by Kix. You can see this by running a SET >%TEMP%\before.txt before you run the EXE, and then a SET >%TEMP%\after.txt after the EXE. The only difference between the files should be that the ClientName is defined in After.txt.
You CAN NOT run the EXE from within kix because it creates a child environment, sets the var into the child environment, and then that environment dies.
The key, as we've been saying, is to find a method that runs from the batch file that determines if the session is run against a Xen client.
Glenn
when running the exe from the bat login file both bofore and after doesn't have the xdclient variable.
|
Top
|
|
|
|
#202489 - 2011-06-22 09:42 AM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
hmm. i just copy and past your script and this seems to work:)
but it gives error : NEXT without FOR!
i did not test it but does this also work on non citrix clients? or goes that code after the NEXT?
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|