从另一个系统访问命名管道时拒绝访问

时间:2010-09-08 11:19:41

标签: c++ windows named-pipes access-denied getlasterror

我有一个命名管道并且工作正常我使用在我的系统上运行的客户端访问它

客户端尝试使用以下代码打开文件:

LPTSTR lpszPipename = TEXT("\\\\smyServerName\\pipe\\iPipe01"); 

      hPipe = CreateFile( 
         lpszPipename,   // pipe name 
         GENERIC_READ |  // read and write access 
         GENERIC_WRITE, 
         0,              // no sharing 
         NULL,           // default security attributes
         OPEN_EXISTING,  // opens existing pipe 
         0,              // default attributes 
         NULL);     


      if (hPipe != INVALID_HANDLE_VALUE) 
         break; 

      // Exit if an error other than ERROR_PIPE_BUSY occurs. 

      if (GetLastError() != ERROR_PIPE_BUSY) 
      {
         _tprintf( TEXT("Could not open pipe. GLE=%d\n"), GetLastError() ); 
         return -1;
      }

创建命名管道时我使用了

lpszPipename = TEXT("\\\\.\\pipe\\iPipe01"); 

而不是myServerName我使用了.(Dot)。当我从另一个系统运行客户端时,我得到了GLE 5(拒绝访问)。

2 个答案:

答案 0 :(得分:1)

首先要检查你的权限和防火墙。几乎总是,当某些东西在本地工作但不在网络上时,它的权限。

(这个问题比我算的多了几倍!)

答案 1 :(得分:1)

AFAIR在Windows Vista中匿名访问命名管道的安全性发生了变化 当您想要从匿名帐户打开它(具有写访问权限)时,您可能必须按照here所述更改管道的安全属性。