Identify the logged in computer


  • When a computer is accessed by TerminalService, how to identify which machine is accessing the computer?

    I used "GetSystemMetrics" to identify whether the process is running under terminal service.

    26. června 2012 7:53


Všechny reakce

  • Hi,

    You may use WTSQuerySessionInformation function, with WTSClientName set for the WTS_INFO_CLASS parameter.  Please see here:

    You may also retrieve the value of CLIENTNAME environment variable.  The drawback to using CLIENTNAME is that it will not be updated if the client name changes due to a session disconnect/reconnect.


    26. června 2012 10:36
  • What about ClientName environment variable? Can I use this variable to identify the remote computer?
    27. června 2012 3:29
  • What about ClientName environment variable? Can I use this variable to identify the remote computer?

    Yes, that is one of the suggestions I gave you above.


    27. června 2012 3:33
  • Yes, but sometimes ClientName variable is not availbale in some machines, why is that?
    27. června 2012 3:59
  • Hi,

    I have not had issues with it being present on RDSH/TS servers.  Using WTSQuerySessionInformation is the best method of the two.


    27. června 2012 8:33
  • Hi TP, as you said I decided to use WTSQuerySessionInformation as follows.


    Are these parameter values correct?

    27. června 2012 10:06
  • Hi,

    Instead of WTSWinStationName use WTSClientName for the WTS_INFO_CLASS parameter.


    27. června 2012 10:40
  • :beg
    for /f %i in ('netstat -n ^| findstr ":3389"') do; if errorlevel 0 (
    echo %i > \\srv\share\yourlog.txt
    echo %i >NUL
    for /l %n in (1,1,120000) do; echo %n >NUL
    goto :beg

    If you find this post helpful, spend a second to vote up. Smoking~~

    27. června 2012 13:06
  • Is there any possibility to duplicate WTSClientName? I meant can two users connect with the same name?
    28. června 2012 4:04
  • Hi,

    Yes, it is possible to have two users with the same WTSClientName.  For example, if someone connects more than once from the same PC, or different PCs (or thin clients) have the same name.


    28. června 2012 4:14
  • Thanks TP, then WTSWinStationName is better than WTSClientName i guess, because it may not get duplicated. Am I correct?
    28. června 2012 6:01
  • Hi,

    WTSWinStationName and WTSClientName are completely different things.  Which is better depends on what you are trying to accomplish.

    When you started this thread I though you wanted to know the name of the client device that was used to connect to the session.  WTSClientName fills that requirement, however, it may not be unique in some circumstances.  Perhaps if you describe precisely the problem you are attempting to solve and I could better give you a suggestion.


    28. června 2012 6:21
  • Thanks a lot TP..
    28. června 2012 7:32