burgerking68
Enthusiast
Enthusiast

Triggered task with Volatile Environment Elements

Jump to solution

Hello,

I would like to create a triggered task in which values are read from the registry during reconnect and written to a text file. Basically, this also works if I call this script in the user context directly on the machine. If I call this batch via a "triggers task" when reconnecting, the corresponding registry entries of the "volatile environment" are missing.
Do you have an explanation for this? Thanks for any answer!

burgerking68_0-1614857223153.png

Batch file:

@Echooff
setlocal
if not exist \\ntapp1\abfragen$\Uptime\User\%Username%\ mkdir \\ntapp1\abfragen$\Uptime\User\%Username%\
echo !! RECONNECT am Datum: %Date%, Uhrzeit %Time% ; Name des entfernten Clients: %ViewClient_Machine_Name% ; IP-Adresse: %ViewClient_IP_Address% ; Anmeldename: %ViewClient_Broker_UserName% ; Protokoll: %ViewClient_Protocol% ; Connection-Server: %ViewClient_Broker_Tags% ; Typ: %ViewClient_Type% ; ViewClientVersion: %ViewClient_Client_Version% ; AnzahlDisplays: %ViewClient_Displays.Number% mit Aufloesung: %ViewClients_Displays.Topology% ; angemeldet an: %computername% >> "\\ntapp1\abfragen$\Uptime\User\%UserName%\%UserName%__%ViewClient_Machine_Name%".txt

Result in txt File after reconnect via triggerd task:
!! RECONNECT am Datum: 04.03.2021, Uhrzeit 12:05:21,89 ; Name des entfernten Clients: ; IP-Adresse: ; Anmeldename: ; Protokoll: ; Connection-Server: ; Typ: ; ViewClientVersion: ; AnzahlDisplays: mit Aufloesung: ; angemeldet an: V10-TRY03

-------------------------------------------

VMWare Horizon 7.12
Windows 10, 1909
DEM 2009

VMWare 7.12, DEM 2009
0 Kudos
1 Solution

Accepted Solutions
DEMdev
VMware Employee
VMware Employee

Hi @burgerking68,

It works for me if I update my script to the following:

@echo off
setlocal
set DumpPath=\\ntapp1\abfragen$\Uptime\User\%Username%\
if not exist %DumpPath% mkdir %DumpPath%
echo !! RECONNECT am Datum: %Date%, Uhrzeit %Time% ; Name des entfernten Clients: %~1 ; IP-Adresse: %~2 ; Anmeldename: %~3 ; Protokoll: %~4 ; Connection-Server: %~5 ; Typ: %~6 ; ViewClientVersion: %~7 ; AnzahlDisplays: %~8 mit Aufloesung: %~9 ; angemeldet an: %computername% >> "%DumpPath%%UserName%__%~1".txt

and pass the following arguments in my triggered task:

"%{ViewClient_Machine_Name}%" "%{ViewClient_IP_Address}%" "%{ViewClient_Broker_UserName}%" "%{ViewClient_Protocol}%" "%{ViewClient_Broker_Tags}%" "%{ViewClient_Type}%" "%{ViewClient_Client_Version}%" "%{ViewClient_Displays.Number}%" "%{ViewClient_Displays.Topology}%"

 

That is, I don't get the broker user name and broker tags filled in as I'm testing using VADC, but the mechanism works. And you (currently...) need exactly 9 arguments, which means the standard %1 .. %9 is just sufficient 🙂

View solution in original post

12 Replies
Mickeybyte
Enthusiast
Enthusiast

@burgerking68 ,

The data in the Volatile Environment keys takes some time to be filled in after logon or reconnect. If you add a sleep/wait statement of about 30 seconds before requesting the data, you should be able to get all the information you need.

 

Regards,
Mickeybyte
0 Kudos
burgerking68
Enthusiast
Enthusiast

Hi, i add a 30-seconds "sleep.exe" bevor execute...but unfortunately I get the same result😒:

%logonserver%\netlogon\sleep.exe 30
echo !! RECONNECT am Datum: %Date%, Uhrzeit %Time% ; Name des entfernten Clients: %ViewClient_Machine_Name% .....

Any other ideas?🤔

VMWare 7.12, DEM 2009
0 Kudos
Mickeybyte
Enthusiast
Enthusiast

I've done it once with updating BGInfo information when they reconnect. If I remember well, I set the sleep to 1 minute and that worked for me.

Maybe start by increasing your sleep timeout to 1 minute just to be sure?

You could also test with your own session: prepare a CMD window and disconnect your session. Next, reconnect and check the environment variables in your cmd window until they become available. That might give you an indication as how long you have to wait before retrieving them.

 

Regards,
Mickeybyte
0 Kudos
burgerking68
Enthusiast
Enthusiast

Hello, I don't think that's a timing problem: if I open a cmd on the corresponding desktop (thanks for that tip @Mickeybyte ), then disconnect the session, then reactivate the session and start the batch from the cmd, I get the desired result immediately. Just not via the triggered task. Here excerpts from the two result txt files. This is what it looks like (in extracts) when it runs correctly

!! RECONNECT am Datum: 04.03.2021, Uhrzeit 16:52:33,34 ; Name des entfernten Clients: TestClient ; IP-Adresse: 10.121.126.12 ; Anmeldename: testuser ; Protokoll: BLAST ;

And this is how it looks when it runs through the triggered tasks on the same vdi-Client:

!! RECONNECT am Datum: 04.03.2021, Uhrzeit 16:52:25,22 ; Name des entfernten Clients: ; IP-Adresse: ; Anmeldename: ; Protokoll: ;

Any other ideas? Thanks!

VMWare 7.12, DEM 2009
0 Kudos
DEMdev
VMware Employee
VMware Employee

Hi @burgerking68,

As @Mickeybyte correctly stated already, the Horizon agent makes those ViewClient_ env vars (and their underlying registry settings) only available shortly after logon and reconnect.
Waiting in your script does not help because of how environment variables work in Windows: when a process starts, it gets its own copy of the env vars. That copy does not automatically get updated when new vars are set later.

It looks like we did not quite document it (I'll take a better look at that later, but I could only find it in the Using Placeholders topic...), but we added a feature in DEM 2009 that allows references to ViewClient info through a new format: %{ViewClient_propertyName}%. Those references can be used "immediately" at logon or reconnect.

If I create a triggered task like this:

DEMdev_0-1614877449435.png

And have a C:\Flex\Dumpargs.cmd batch file with the following content:

@echo off
(
echo %1
echo %2
echo %3
) >> "%USERPROFILE%\args.txt"

That args.txt file is correctly updated at each reconnect. (I used that ViewClient_DemoValue as an easy way to force an update to the client properties between reconnects; it does not exist by default :-).)

0 Kudos
Mickeybyte
Enthusiast
Enthusiast

Referring to my use case, I did not use DEM, but a GPO that created a scheduled task with a trigger "at reconnect" and a delay of 1 min. So, when a user reconnects, the scheduled tasks kicks in, but with a delay of 1min. This solved the issue for me and the environment variables were available. 

Not shore about the DEM triggered task, but is it running as the logged in user? Try adding "%username%" in your list of variables you export to make sure it is. If it is, then you could split up your script into 2 files. The first one that is triggered by the reconnect does a wait of 1min and then calls your second script which does the export of the variables.

Or use the solution as proposed by @DEMdev , but looking at the amount of variables you want to save, that might be a long argument list 😉

 

 

Regards,
Mickeybyte
0 Kudos
DEMdev
VMware Employee
VMware Employee

Hi @Mickeybyte,

Yeah, I suppose that scheduled task scenario would work. I'll take a look to see how much effort it would take to add an optional "delay" to the triggered task mechanism as possible future change.

Executables launched from a DEM triggered task are run as the logged-on user. But that two-step approach won't work either: that second process would inherit a copy of its parent's env vars 😞

Fair point that @burgerking68 would have quite a few command-line arguments to add to their batch file 🙂

0 Kudos
burgerking68
Enthusiast
Enthusiast

Thank you both, I'll have a look at the weekend if I can get the DEMDev proposed to work in my area

 

 

VMWare 7.12, DEM 2009
0 Kudos
DEMdev
VMware Employee
VMware Employee

Hi @burgerking68,

It works for me if I update my script to the following:

@echo off
setlocal
set DumpPath=\\ntapp1\abfragen$\Uptime\User\%Username%\
if not exist %DumpPath% mkdir %DumpPath%
echo !! RECONNECT am Datum: %Date%, Uhrzeit %Time% ; Name des entfernten Clients: %~1 ; IP-Adresse: %~2 ; Anmeldename: %~3 ; Protokoll: %~4 ; Connection-Server: %~5 ; Typ: %~6 ; ViewClientVersion: %~7 ; AnzahlDisplays: %~8 mit Aufloesung: %~9 ; angemeldet an: %computername% >> "%DumpPath%%UserName%__%~1".txt

and pass the following arguments in my triggered task:

"%{ViewClient_Machine_Name}%" "%{ViewClient_IP_Address}%" "%{ViewClient_Broker_UserName}%" "%{ViewClient_Protocol}%" "%{ViewClient_Broker_Tags}%" "%{ViewClient_Type}%" "%{ViewClient_Client_Version}%" "%{ViewClient_Displays.Number}%" "%{ViewClient_Displays.Topology}%"

 

That is, I don't get the broker user name and broker tags filled in as I'm testing using VADC, but the mechanism works. And you (currently...) need exactly 9 arguments, which means the standard %1 .. %9 is just sufficient 🙂

View solution in original post

burgerking68
Enthusiast
Enthusiast

Hi @DEMdev , that works for me!  Thanks for your work on this.

Greetings...and enjoy the weekend:

VMWare 7.12, DEM 2009
0 Kudos
burgerking68
Enthusiast
Enthusiast

Hello,

the above goes so far. But now the "master question": The triggered task is currently only set to "Session reconnected". If I run the same script with "Session disconnected", none of the arguments in the script are processed. This is probably due to the fact that the corresponding values ​​can no longer be accessed when disconnecting. Do you have a solution for that?

--------------

VMWare 7.12, DEM 2009
0 Kudos
DEMdev
VMware Employee
VMware Employee

Hi @burgerking68,

At disconnect, the Horizon agent removes the client properties. You'd have to "remember" them at logon and reconnect to be able to log them at disconnect.

0 Kudos