Identify the logged in computer
-
26. června 2012 7:53
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.
Všechny reakce
-
26. června 2012 10:36Moderátor
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
- Navržen jako odpověď TP []MVP, Moderator 27. června 2012 3:33
- Označen jako odpověď DevNC 28. června 2012 7:32
-
27. června 2012 3:29What about ClientName environment variable? Can I use this variable to identify the remote computer?
-
27. června 2012 3:33ModerátorWhat 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:59Yes, but sometimes ClientName variable is not availbale in some machines, why is that?
-
27. června 2012 8:33Moderátor
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 10:06
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:40Moderátor
Hi,
Instead of WTSWinStationName use WTSClientName for the WTS_INFO_CLASS parameter.
-TP
-
27. června 2012 13:06
: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 :begIf you find this post helpful, spend a second to vote up. Smoking~~
-
28. června 2012 4:04Is there any possibility to duplicate WTSClientName? I meant can two users connect with the same name?
-
28. června 2012 4:14Moderátor
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 6:01Thanks TP, then WTSWinStationName is better than WTSClientName i guess, because it may not get duplicated. Am I correct?
-
28. června 2012 6:21Moderátor
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 7:32Thanks a lot TP..