question

TZacks-2728 avatar image
1 Vote"
TZacks-2728 asked DanielZhang-MSFT commented

c# How to get actual user id & IP when user Connect to other PC via remote desktop

I have a one server and a c# based console application is running there. Now there are 5 users who login to server via remote desktop using same admin login.

i want when any user close my console application running on server then i want to log the user id and ip in a text file. so how to get user id & IP of user pc from console application running on server who login there via remote desktop?

please guide me.

Thanks

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AdnaneARHARBI-3917 avatar image
1 Vote"
AdnaneARHARBI-3917 answered DanielZhang-MSFT commented

Hi;
Develop in C # a windows service which looks for open remote ports: "netstat -ano" then log this information in a file or a windows log.
as keywords to search: netstat, windows service with c #.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry do not understand what are you saying ?

how to capture logged in user id/IP from the application running in server and user connect there via remote desktop. so how to get user's actual user id or IP from server? is it possible ?

0 Votes 0 ·

You could use the netstat command to get information about which IP addresses and ports your machine is communicating with. You could run this command on a regular basis and parse the text output.

You can call this command from .Net using System.Diagnostics.Process and parse the text output, e.g:

system.diagnostics.process.standardoutput.aspx

and combine with the SID: S-1-5-5-X-Y Name: Logon Session Description: A logon session. The X and Y values for these SIDs are different for each session.

Well-known security identifiers in Windows operating systems:

security-identifiers






0 Votes 0 ·

How to execute netstat command using c# and parse output data from where my objective is to parse IP address from user came from and user pc name etc.

please provide a sample code. thanks

0 Votes 0 ·
Show more comments
Castorix31 avatar image
1 Vote"
Castorix31 answered Evgenij-Smirnov commented

I cannot test for your particular case, but it should work with WTS Apis (P/Invoke), mainly
WTSEnumerateSessions
WTSQuerySessionInformation


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is the cleanest and most reliable way to get that information. You're not going to get the username that is logged on on the endpoint though.

0 Votes 0 ·