c++winapinamed-pipes

CreateNamedPipe causes ERROR_ACCESS_DENIED?


i need to create a named pipe for communication between client and server (in same host), here is the code:

WCHAR wszPipeName[MAX_FILE_LENGTH];
swprintf_s(wszPipeName, MAX_FILE_LENGTH, L"\\\\.\\pipe\\TEST%d", uniqueID);
pipe = CreateNamedPipe(
           wszPipeName, // name of the pipe
           PIPE_ACCESS_DUPLEX,
       PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
       1,
           MAX_MSG_SIZE, 
           MAX_MSG_SIZE , //inbound buffer
           MAX_READ_DATA_TIMEOUT,
           NULL // use default security attributes
       );

It the handler get back is always INVALID_HANDLE_VAULE, and the error is ERROR_ACCESS_DENIED.

Is there anything wrong here? It is running on Windows 7/8.

Thanks


Solution

  • Found the reason, it is because the security limitation. After providing a suitable security descriptor, it just works!