我不知道为什么我会收到ERROR_NOT_FOUND
/ 1168 (0x490) 错误代码。如果我替换GetNamedPipeClientProcessId
为GetNamedPipeServerProcessId
,我成功地获得了服务器的进程 ID。
代码:
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetNamedPipeClientProcessId(IntPtr Pipe, out int ClientProcessId);
int GetNamedPipeClientProcessId(NamedPipeServerStream pipeServer)
{
var hPipe = pipeServer.SafePipeHandle.DangerousGetHandle();
if (GetNamedPipeClientProcessId(hPipe, out var clientProcessId))
{
return clientProcessId;
}
else
{
var error = Marshal.GetLastWin32Error();
return 0;
}
}
您需要GetNamedPipeClientProcessId
在客户端调用CallNamedPipe
或CreateFile
连接到名称管道后调用。如果客户端还没有连接到名称管道,GetNamedPipeClientProcessId
将失败ERROR_NOT_FOUND
(0x490)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句