none
Identify the logged in computer

    Dotaz

  • 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

Odpovědi

Všechny reakce

  • Hi,

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

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa383838(v=vs.85).aspx

    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.

    -TP

    26. června 2012 10:36
    Moderátor
  • 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.

    -TP

    27. června 2012 3:33
    Moderátor
  • 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.

    -TP

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

    WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSWinStationName, , )

    Are these parameter values correct?

    27. června 2012 10:06
  • Hi,

    Instead of WTSWinStationName use WTSClientName for the WTS_INFO_CLASS parameter.

    -TP

    27. června 2012 10:40
    Moderátor
  • :beg
    for /f %i in ('netstat -n ^| findstr ":3389"') do; if errorlevel 0 (
    echo %i > \\srv\share\yourlog.txt
    )ELSE(
    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.

    -TP

    28. června 2012 4:14
    Moderátor
  • 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.

    -TP

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