Tech Support > Microsoft Windows > Development Resources > Named Pipes in Service doesnt work ?
Named Pipes in Service doesnt work ?
Posted by Niel Darren on November 13th, 2007


Hello,

Got a big problem - got some applications running where i use named pipes to
recieve and send messages, it is working perfect when they are running as
applications, but if i let them run as service then the pipes suddenly
doesnt work - so i have to do something wrong:

The way i had it working fine in the application was this:

PipeHandle = CreateNamedPipe(PipeUNCname, PIPE_ACCESS_INBOUND,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, 0, 0,
PIPE_BUFSIZE, NULL ));

And then launched a new thread for each incoming connection, that was
working fine.

Then i put the application into a service-shell, and then it didnt work, i
could see with pipelist.exe that the pipe was created, but any:

hFile = CreateFile(szPipe, GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);

And write to them would fail.

Reading abit about it on the internet i saw things about the SD, and i then
tried to create my pipe with:

SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;

InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPT OR_REVISION);
SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE);
SetSecurityDescriptorGroup(&sd,NULL, FALSE );
SetSecurityDescriptorSacl(&sd, FALSE, NULL, FALSE );

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
PipeHandle = CreateNamedPipe(PipeUNCname, PIPE_ACCESS_INBOUND,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, 0, 0,
PIPE_BUFSIZE, &sa ));

Do i have to do something special on the writer side - is that where it is a
problem ?

But it didnt change anything, and i still cannot get them to work, unless i
run it as an ordinary app and not a service.

I really hope someone can help, its pretty annoying and i have no idea what
im doing wrong - im running XP & 2K & WIN 2003 server.

Maybe somebody have an example that they can "promise" would work in a
service, client and serverside ? or maybe you just know exactly whats wrong


Thanks !



Similar Posts