我不确定如果我只是没有看到它或什么?我需要知道从NamedPipeServerStream
实例通过命名管道连接到我的服务器的客户端的进程ID。这样可能吗?获取使用C#连接到命名管道服务器的客户端的进程ID
在此期间,我想出了这个功能:
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetNamedPipeClientProcessId(IntPtr Pipe, out UInt32 ClientProcessId);
public static UInt32 getNamedPipeClientProcID(NamedPipeServerStream pipeServer)
{
//RETURN:
// = Client process ID that connected via the named pipe to this server, or
// = 0 if error
UInt32 nProcID = 0;
try
{
IntPtr hPipe = pipeServer.SafePipeHandle.DangerousGetHandle();
GetNamedPipeClientProcessId(hPipe, out nProcID);
}
catch
{
//Error
nProcID = 0;
}
return nProcID;
}
我不是在“DangerousGetHandles”和“DllImports”非常强。用Win32,我在这里使用的方式更好。
实际上你的问题是什么? – ken2k 2013-04-09 08:04:52
你想知道“这是正确的”吗?或者是什么? – Ben 2013-04-09 08:56:46
我最关心的是他们所谓的“DangerousGetHandle”。 – c00000fd 2013-04-09 09:45:47