none
Identify the logged in computer

    Pregunta

  • 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.

    martes, 26 de junio de 2012 7:53

Respuestas

Todas las respuestas

  • 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

    • Propuesto como respuesta TP []MVP, Moderator miércoles, 27 de junio de 2012 3:33
    • Marcado como respuesta DevNC jueves, 28 de junio de 2012 7:32
    martes, 26 de junio de 2012 10:36
  • What about ClientName environment variable? Can I use this variable to identify the remote computer?
    miércoles, 27 de junio de 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

    miércoles, 27 de junio de 2012 3:33
  • Yes, but sometimes ClientName variable is not availbale in some machines, why is that?
    miércoles, 27 de junio de 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

    miércoles, 27 de junio de 2012 8:33
  • 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?

    miércoles, 27 de junio de 2012 10:06
  • Hi,

    Instead of WTSWinStationName use WTSClientName for the WTS_INFO_CLASS parameter.

    -TP

    miércoles, 27 de junio de 2012 10:40
  • :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~~

    miércoles, 27 de junio de 2012 13:06
  • Is there any possibility to duplicate WTSClientName? I meant can two users connect with the same name?
    jueves, 28 de junio de 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

    jueves, 28 de junio de 2012 4:14
  • Thanks TP, then WTSWinStationName is better than WTSClientName i guess, because it may not get duplicated. Am I correct?
    jueves, 28 de junio de 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

    jueves, 28 de junio de 2012 6:21
  • Thanks a lot TP..
    jueves, 28 de junio de 2012 7:32