我不确定我是否没有看到它,或者是什么? 我需要知道从NamedPipeServerStream实例通过命名pipe道连接到我的服务器的客户端的进程ID。 这样可能吗?
同时我想出了这个function:
[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,我在这里使用更好。
在本地运行Azure模拟器进行生产
为什么这个Cancellationdisposable永远不会取消Observable.dispose()?
使用安装程序更新Windows .net程序
WorkbookOpen事件与Windows服务没有触发,而它与Windows应用程序触发
如何将绝对系统path转换为IShellFolder?
是否有可能在VB.net中包含两个具有相同名称的DLL库?
通过远程桌面提高WPF应用程序的速度?
确保生成的进程的窗口在主应用程序的前面?
在C#中使用访问器有什么优点和缺点?
该代码的主要问题是它不执行正确的错误处理。 您需要检查GetNamedPipeClientProcessId的返回值以检测错误。
[DllImport("kernel32.dll",out uint ClientProcessId); public static uint getNamedPipeClientProcID(NamedPipeserverStream pipeserver) { UInt32 nProcID; IntPtr hPipe = pipeserver.SafePipeHandle.DangerousGetHandle(); if (GetNamedPipeClientProcessId(hPipe,out nProcID)) return nProcID; return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。