views:

37

answers:

2

Hi. For example i create socket using winsock under account named Admin. Is there any possibility to detect which user created that socket? I would like to write in my program: This socket was created by "Admin". i am using c++

A: 

netstat -o should give you process IDs which created the socket; from there, you can find the process owner. If everything else fails, you could spawn netstat in a new process and parse the output.

Piskvor
+1  A: 

Sockets are not securable objects (see here) and so cannot have a security descriptor associated with them and so there's no way you can know the user account that 'created the socket'.

You could use GetExtendedTcpTable to get information about connections and then locate the PID of the process that created the socket; you could then decide to use something based on the process...

Why do you want to do this anyway?

Len Holgate
when i get app socket using LSP, need to know the name of the user that ran the application which is using this socket
Roar
That's a subtly different question, you can use GetExtendedTCPTable for that, I expect; that will give you the PID then you can query the process for the info you need.
Len Holgate