Page 2 of 5 <12345>
Topic Options
#202363 - 2011-05-27 01:26 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
I've corrected the typo's in my example. Sorry - I must have lost a char when I cut/paste parts of the original script.

The problem with Mart's example is that it performs the Citrix detection and runs the command to set the environment var from Kix. This won't work because the value is set in the child environment of the Run/Shell command, where it will disappear when the comand ends. The environment var must be set BEFORE Kix runs. There's no benefit of detecting physical or XEX session state within kix for your requirement.

Further - my "IIF" example will work and will not require any additional logic.

When you are on a regular PC and run the login script, the %XDClientName% will be empty. This causes the IIF logic to evaluate to "FALSE" and return the @WKSTA value. The command run from the bat file (or not, if you add the detection process there) will insure that the environment variable is not set.

However, when you login to a Xen session, the batch file runs the command which successfully sets the environment var. When the Kix script runs, the IIF evaluates to TRUE and returns the environment variable.

Either way, the $computerprt will contain the name of the PHYSICAL computer that the user is sitting at. Take the first six chars and continue with your code to determine the location and map the printers.

Now, for diagnostics..
In your Batch file, BEFORE you call the Kix script, add the line
 Code:
Set > %TEMP%\%USERNAME%_env.txt
This will capture the user's login environment settings to a file. Go to that folder after you log in and open it. Verify that the XDClientName variable is defined, and if so, is defined the way you expect. If it isn't, you need to troubleshoot the XD4ClientName.exe command.

Add the line
 Code:
'XD Client Name: ' %XDClientName% @CRLF
to your Kix script to verify that it sees the proper var value. Add this just before the IIF statement in my example. Add another debug message after the IIF block to view the contents of the $computerprt var. The end result should be:
 Code:
'XD Client Name: ' %XDClientName% @CRLF
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = Left($ComputerPrt, 6)
'ComputerPrt: $ComputerPrt @CRLF
If this doesn't work, post the contents of the %TEMP%\%USERNAME%_env.txt file and a screenshot of the debug messages from the code above.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202364 - 2011-05-27 01:36 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
One more thing.. Since Xen is VDI and not the same as a Citrix RDP session, the use of session type detection AND forcing it to be ICA format may not be valid. I'll be able to get into the lab this afternoon and confirm what the sessiontype returns on our Xen system, but for what you want to do, it just complicates things - remove it for now.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202365 - 2011-05-27 02:30 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

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


If you use the code Brad posted then you need to include the SessionType UDF. It will not work without the UDF. The ICA part comes from the UDF. It checks the session the user is in and returns RDP (remote desktop), ICA (Citrix) or CON (console).


Edited by Mart (2011-05-27 02:31 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202366 - 2011-05-27 02:36 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Mart,

Have you confirmed that it will return "ICA" from a Xen Desktop connection under all conditions?

This isn't a traditional Citrix server, and I don't connect to my Xen server using an ICA client, so this may be messing withthings a bit.. That's why I sugggest avoiding the session-type determination entirely.

If the env var is set, the session is a Xen system and the var contains the client computer name, otherwise it is blank. This keeps the process simple, since all that's needed is to identify the client computer name to determine the user's physical location.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202367 - 2011-05-27 03:10 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Sorry, I do not have any Xen servers but I assumed that it works. Might not be 100% correct. I do not have any Xen servers so I'm unable to test.

Is anybody using Xen servers and able to do a small test?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202368 - 2011-05-27 03:52 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You must be suffering from springtimeitis.. I noted that I have a Xen server, which is why I stated that "I don't connect using an ICA client..." \:D

I know it's been a long, cold winter, but stop staring out the window at the pretty women and pay attention (at least momentarily) to the task at hand.

I'll get back to my office this afternoon and verify what is actually reported from the Xen server. I've been on the road for a few days and haven't had time. I'm concerned that - unlike a traditional Citrix server - there are multiple connection methods for Xen and they might not all report the same condition in SessionType.

Glenn

PS - feel free to resume daydreaming \:\) I'm out in an hour and looking forward to a 3.5 day weekend and my own daydreaming!
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202369 - 2011-05-27 04:56 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: Glenn Barnas
You must be suffering from springtimeitis.. I noted that I have a Xen server, which is why I stated that "I don't connect using an ICA client..." \:D

I know it's been a long, cold winter, but stop staring out the window at the pretty women and pay attention (at least momentarily) to the task at hand.
....


SIR YES SIR!

LOL yeah. The weather is ok, it has been a rough week and it is almost weekend so I might be a little distracted.
Let me know what you find on your Xen server. If it is possible I'll update the UDF to report RDP, CON, ICA or XEN (or whatever comes out).

kr,
Marty
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202370 - 2011-05-27 06:48 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
On a side note...Did a bit of testing here...The XDClientName.exe throws an error when run on the PC side since it is trying to use a dll that is only present on citrix servers. So may have to verify that its a server in the BAT file before running.
Top
#202371 - 2011-05-27 09:47 PM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Another idea...You may be able to avoid using the XDClientName.exe altogether if someone can figure out how to connect to the wfAPI library via kix? If that's possible?

http://community.citrix.com/display/xa/How+to+get+Client+IP+and+hostname+using+Citrix+WFAPI+SDK

Top
#202372 - 2011-05-27 11:34 PM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Shane,

Yeah, I noted that.. that's why it takes 3-4 seconds before returning with an error. Still, it did not populate the environemnt var. Not the cleanest solution, but would get through initial testing.

I'll look at your other recommendation - I might have some time in the coming days to try some things on our test Xen server.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202373 - 2011-05-27 11:47 PM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Yea the 3-4 seconds isn't bad. But on my xp machine it actually halted with a popup error asking to send the error to microsoft lol. Sorry I couldn't do more testing. No servers to test on.
Top
#202374 - 2011-05-28 02:48 AM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Hmm.. I ran it from the command line - got an error after a few seconds, but no popup. If you run it from Explorer with double-click, that might be the case, but that doesn't represent the environment of a bat file.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202375 - 2011-05-28 03:06 AM Re: how to read a custom environment variable (XDClientName) [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
It was actually via a bat file (was trying to replicate the setup). It also does same thing on my windows 7 laptop. Get the 'XDClientName has stopped working' box with options to check online for solution or to close the program. After I close that box, the expected error shows in the cmd window. But regardless...just my observations. There has got to be a better way to get this info from the server via kix alone. Im not familiar with xen, but would the old wtsmanager work in that environment?

http://kixhelp.com/wr/files/kixtart/wtsmanager.zip

Top
#202376 - 2011-05-28 05:57 PM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Got to thinking about this more...I cant get the xdclientname.exe to run on my system so i dont know the exact syntax of what it displays, but according to the docs it does display the client name on the console...SO...Why not use WshPipe to get it? And of course there is still the fact of only running on a server...so still need to figure out how to distinguish servers from desktops. But something like this should work in theory?...

 Code:
If $xen
   $computerprt = Join(WshPipe(@ScriptDir+"\XD4ClientName.exe",1))
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")
   Case 1
endselect

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
	Dim $oExec, $Output
	$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
	If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
	$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
	If Not $NoEcho $Output Endif
	$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
	Exit($oExec.ExitCode)
EndFunction

Top
#202380 - 2011-05-30 09:25 AM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
@Glenn

I've test it a couple of times and it works. but indeed i get the popup error asking to send the error to microsoft lol.

any way to fix this?

Top
#202381 - 2011-05-30 09:30 AM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: arjanv
@Glenn

I've test it a couple of times and it works. but indeed i get the popup error asking to send the error to microsoft lol.

any way to fix this?


Not with Kix.
You'll have to ask the developer what is going on and if it can be fixed.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202384 - 2011-05-30 04:22 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
is it an idea to add a wait/pause in the bat file before xdclientname is loading?
Top
#202385 - 2011-05-30 04:39 PM Re: how to read a custom environment variable (XDClientName) [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
You can always try. I guess it will not fix the error but some testing doesn't hurt.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#202386 - 2011-05-30 06:16 PM Re: how to read a custom environment variable (XDClientName) [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
i think the WshPipe method may work fine eliminating the need for a bat altogether, all thats needed is a way to keep it only running on the servers.
Top
#202413 - 2011-06-06 10:12 AM Re: how to read a custom environment variable (XDClientName) [Re: ShaneEP]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
i've tried this, but doesn't work at all.

 Code:
If $xen
   $computerprt = Join(WshPipe(@ScriptDir+"\XD4ClientName.exe",1))
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")
   Case 1
endselect

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
	Dim $oExec, $Output
	$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
	If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
	$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
	If Not $NoEcho $Output Endif
	$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
	Exit($oExec.ExitCode)
EndFunction
 


anyone a solution, i'm desperate:(

Top
Page 2 of 5 <12345>


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.208 seconds in which 0.094 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org