Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Named Pipes in Windows Service ?!

Posted on 2007-11-14
5
Medium Priority
?
1,206 Views
Last Modified: 2013-12-04
Can anybody show me how to do a named pipe server / client in a windows service ? i have a pipeserver in an app running on XPSP2 and Win2K / 2003 that works fine as an application, but as soon as i encapsulate it in a service the client dont seem to be able to write to it anymore ??

Really hope someone can help, its urgent. Thanks
0
Comment
Question by:thordk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 20286142
How are you setting the security attributes of the pipe? Try

SECURITY_DESCRIPTOR         sd;
PSID psidWorldSid; // a SID representing "everyone"
SID_IDENTIFIER_AUTHORITY siaWorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;

psidWorldSid = (PSID) LocalAlloc(LPTR, GetSidLengthRequired(1));
InitializeSid(psidWorldSid, &siaWorldSidAuthority, 1);
*(GetSidSubAuthority(psidWorldSid, 0)) = SECURITY_WORLD_RID;

if  (   !InitializeSecurityDescriptor   (   &sd,    SECURITY_DESCRIPTOR_REVISION)
    )
    {
        //  error
    }

// here I set the _group_ to 'world', but you could also use
// 'owner'...
if  (   !SetSecurityDescriptorGroup (   &sd,    psidWorldSid,   TRUE)
    )
    {
        //  error
    }

SECURITY_ATTRIBUTES sa;

sa.nLength                        =      sizeof      (      SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor      =      &sd;
sa.bInheritHandle            =      FALSE;
0
 

Author Comment

by:thordk
ID: 20326911
Hi jkr !

Thanks for answering - i havent used the SD at all in my applications, but then i read somewhere that it was important if they were running as a service (can you confirm that ?). What i tried to put into as a service was:

SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;

InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_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 ));

- But do i have to something both on serverside and clientside ? some of the clients will run as services too.
0
 
LVL 86

Expert Comment

by:jkr
ID: 20329174
Yes, you should try that for both ends of the pipe.
0
 

Author Comment

by:thordk
ID: 20329895
Okay just to get it right; ill use the exact same SD in both end right ? i will try to make a test and return back to you, thanks alot.
0
 

Author Comment

by:thordk
ID: 20345880
That appeared to have solved my problem ! thanks alot.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question