Page 4 of 5 <12345>
Topic Options
#202440 - 2011-06-08 11:52 PM Re: how to read a custom environment variable (XDClientName) [Re: Arend_]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2081
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
 Code:
@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
 Code:
$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 Offline
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
#202443 - 2011-06-09 03:16 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
I think kix is able to get the name of the server using @wksta but there is now ay to be sure without testing.
Placing a file on the c drive can also be an option.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202444 - 2011-06-09 04:02 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
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.
 Code:
$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?

 Quote:

$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
#202445 - 2011-06-09 04:32 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Great that at least a part of it is working. The script below should do the trick for adding the printers.
The $rc = in front of the AddPrinterConnection and SetdefaultPrinter lines will catch the return codes of these function so they do not show on the screen.

 Code:
$ComputerPrt = Left(@wksta, 6)
If $ComputerPrt = "VA-CTX"
	Run "\\server\netlogon\XDClientName.exe"
	$client ExpandEnvironmentVars(%xdclientname%)
	Select
		Case Left($client, 6) "LA-ROO"
			$rc = AddPrinterConnection("\\VA-PRN-001\printer1")
			$rc = SetDefaultPrinter("\\VA-PRN-001\printer1")
		Case Left($client, 6) "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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202446 - 2011-06-10 11:55 AM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
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.
 Quote:

$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
#202447 - 2011-06-10 12:33 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
There are many ways to debug. You can use the /d parameter when starting the script but what I usually do is display some key variables on the screen by adding ?$varname just after they are set and/or modified. Adding some text might also help. If you add something like ?"Yep system name is xxxx" in the case statements you will see what case resolves to true (if any). Adding a Case 1 statement as the last Case will enable you to show or do something when all others fail. If all other case statements fail Case 1 will always be executed. Adding a sleep at the end will enable you to actually see the stuff on the screen.

A small example:
 Code:
Break on

$test = 1
? $test

$test = $test + 5
? $test

Select
	Case $test = 1
		? "Test equals 1"
		;Do stuff for 1.
	Case $test = 7
		? "Test equals 7"
		;Do stuff for 7
	Case 1
		? "All cases failed. Test equals: " + $test
		;Do stuff for everything but 1 and 7.
EndSelect

Sleep 10
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202448 - 2011-06-10 01:16 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
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 Offline
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 Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
 Originally Posted By: arjanv
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.

 Quote:

....
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

 Quote:

....
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.
 Code:
$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
#202451 - 2011-06-10 05:32 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2081
Loc: Tulsa, OK
 Quote:
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.


This is why I suggested checking for server in the Bat file in my post above (top of page 4).

Top
#202452 - 2011-06-10 07:26 PM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
Glenn Barnas Administrator Online   content
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202453 - 2011-06-10 10:20 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2081
Loc: Tulsa, OK
Would changing your BAT file to this get rid of the popup error?
 Code:
@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...
 Code:
$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 Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: Mart
 Originally Posted By: arjanv
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.

 Quote:

....
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

 Quote:

....
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.
 Code:
$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 Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: Glenn Barnas
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
#202485 - 2011-06-21 04:07 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
It might be a bit tricky but enumerating the registry key and checking the name might work. This only work if there is just one sub key in HKLM\software\citrix\PortICA\uxpersistence\.

 Code:
$index = 0
$keyname = EnumKey("HKLM\software\citrix\PortICA\uxpersistence\", $index)
While @ERROR = 0
	Select
		Case InStr($keyname, "LA-DOC")
			;set printers
		Case InStr( $keyname, "LA-ROO")
			;set printers
		Case InStr($keyname, "aaaaaa")
			;set printers
	EndSelect
	$Index = $Index + 1
Loop


Edited by Mart (2011-06-22 08:54 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202487 - 2011-06-21 07:34 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2081
Loc: Tulsa, OK
While...Next?
Top
#202488 - 2011-06-22 08:58 AM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
 Originally Posted By: ShaneEP
While...Next?


oops my bad. Had a sh#tty day day of very poor quality yesterday and did a quick and dirty code as an example. Fixed thanks.


Edited by Mart (2011-06-22 09:56 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202489 - 2011-06-22 09:42 AM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
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
#202490 - 2011-06-22 09:52 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
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.


Edited by Mart (2011-06-22 09:55 AM)
Edit Reason: Added some stuff.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 4 of 5 <12345>


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

Who's Online
0 registered and 59 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.047 seconds in which 0.012 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