Solved

Named Pipes in Windows Service ?!

Posted on 2007-11-14
5
1,190 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…

735 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