将 ConnectNamedPipe() 从 XP 迁移到 Win 7 时出现问题
我们开发了一个 XP 应用程序,该应用程序在阻塞模式下使用 ConnectNamedPipe()。
在 Win 7 上进行测试时,应用程序的行为就像未受阻止一样:ConnectNamedPipe() 在其 VBS 客户端连接之前返回。调用 StreamReader.ReadLine() 时会引发异常(“等待进程打开管道的另一端”)。当使用调试器运行时,即使在 Win 7 中也不会发生这种情况!
这些是我们正在使用的函数: [
DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeFileHandle CreateNamedPipe(
String pipeName,
uint dwOpenMode,
uint dwPipeMode,
uint nMaxInstances,
uint nOutBufferSize,
uint nInBufferSize,
uint nDefaultTimeOut,
IntPtr lpSecurityAttributes);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int ConnectNamedPipe(
SafeFileHandle hNamedPipe,
IntPtr lpOverlapped);
在我们写完这篇文章之后,我们从 CodePlex 一体式代码框架示例中找到了一个 MS 示例,该示例执行此操作:(我们现在正在尝试此操作)
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern SafePipeHandle CreateNamedPipe(string pipeName,
PipeOpenMode openMode, PipeMode pipeMode, int maxInstances,
int outBufferSize, int inBufferSize, uint defaultTimeout,
SECURITY_ATTRIBUTES securityAttributes);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool ConnectNamedPipe(SafePipeHandle hNamedPipe,
IntPtr overlapped);
有人对方向有想法吗?可能与安全有关吗?谢谢。
We developed an XP application that uses ConnectNamedPipe() in blocking mode.
When testing on Win 7, the application behaves as if it is unblocked: ConnectNamedPipe() returns before its VBS client connects. An exception is raised ("Waiting for a process to open the other end of pipe") when calling StreamReader.ReadLine(). When running with the debugger, this does not occur even in Win 7!
These are the functions that we are using:
[
DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeFileHandle CreateNamedPipe(
String pipeName,
uint dwOpenMode,
uint dwPipeMode,
uint nMaxInstances,
uint nOutBufferSize,
uint nInBufferSize,
uint nDefaultTimeOut,
IntPtr lpSecurityAttributes);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int ConnectNamedPipe(
SafeFileHandle hNamedPipe,
IntPtr lpOverlapped);
After we wrote this, we found an MS example from the CodePlex All-In-One Code Framework Samples that does this: (we are trying this now)
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern SafePipeHandle CreateNamedPipe(string pipeName,
PipeOpenMode openMode, PipeMode pipeMode, int maxInstances,
int outBufferSize, int inBufferSize, uint defaultTimeout,
SECURITY_ATTRIBUTES securityAttributes);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool ConnectNamedPipe(SafePipeHandle hNamedPipe,
IntPtr overlapped);
Does anyone have an idea for a direction? Could it be security related? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MS All-In-One Code Framework 提供的代码示例(用于 IPC 的 C# 命名管道服务器 (CSNamedPipeServer) )显示了执行此操作的正确方法,并且它适用于 Win 7。
The code sample provided by MS All-In-One Code Framework (C# named-pipe server for IPC (CSNamedPipeServer)) shows the correct way how to do this and it works on Win 7.