Clientame environment variable from RDP missing

Paco Gaspar 91 Reputation points
2021-03-16T15:45:48.947+00:00

Hi, I manage several dozens of Windows Servers. I have an script which, whenever an administrator logs on one server via Remote Desktop, captures the user name and the computer from where he logs in. For computer, the script uses the CLIENTNAME environment variable. We have 2008, 2012 and 2016 servers. There are 2016 servers where the script doesn't works, but not always. I mean, some 2016 servers, never report clientname, other 2016 servers, sometimes don't report, sometimes yes. I am not able to find a pattern. When the script doesn't report the clientname, I log on to the server via RDP and type Set Clientname from CMD or $env:clientname from Powershell and it shows as null. I have googled it and I have found several articles pointing to a configuration in flie explorer that launchs folder windows in a separate process, but I have it unselected in all my servers. How can I make clientname environment variable to work always, or if it is not possible, how can I get the clientame with a vbs or powershell script at logon time? Thanks

Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,391 questions
0 comments No comments
{count} votes

Accepted answer
  1. Grace HE 1,241 Reputation points
    2021-03-17T07:18:12.153+00:00

    Hi,
    Thank you for posting your query. According to your description, here are some suggestions you may try to fix it.

    $sessionID = (Get-Process -PID $pid).SessionID
    $sessionCLIENTNAME = (Get-ItemProperty -path ("HKCU:\Volatile Environment\" + $sessionID) -name "CLIENTNAME").CLIENTNAME

    Best Regards,
    Grace

    ---If the suggestions above are helpful, please ACCEPT ANSWER. Really appreciate. This will also help others with similar issue to find this post quickly. ---

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Paco Gaspar 91 Reputation points
    2021-03-17T10:35:29.643+00:00

    Thanks for the suggestion, I will try tomorrow.


  2. Paco Gaspar 91 Reputation points
    2021-03-18T08:54:24.217+00:00

    The script works, thank you.

    I keep the doubt: Why some servers create the environment variable and others don't?

    0 comments No comments