#202363 - 2011-05-27 01:26 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
|
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 lineSet > %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 '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:'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!
|
Top
|
|
|
|
#202375 - 2011-05-28 03:06 AM
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
|
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
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?...
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
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
|
|
|
|
#202384 - 2011-05-30 04:22 PM
Re: how to read a custom environment variable (XDClientName)
[Re: Mart]
|
arjanv
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
|
|
|
|
#202413 - 2011-06-06 10:12 AM
Re: how to read a custom environment variable (XDClientName)
[Re: ShaneEP]
|
arjanv
Fresh Scripter
Registered: 2010-03-11
Posts: 49
Loc: netherlands
|
i've tried this, but doesn't work at all.
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|