Search code examples
c++windowsnamed-pipesaccess-deniedgetlasterror

Getting Access Denied While Accessing the Named Pipe from Another System


I have a Named Pipe and It Works Fine While I access it using a Client which runs on My System

The Client tries to open the File using following code:

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;
      }

While Creating the Named Pipe I have used

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

Instead of myServerName I have used .(Dot). I get GLE 5 (Access denied) while I run the client from another system.


Solution

  • First things first - check your permissions and firewall. Almost always, when something works locally but not on the network, it's permissions.

    (Had this problem more times than I can count!)