Solved

Named Pipes in Windows Service ?!

Posted on 2007-11-14
5
1,179 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
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, you should try that for both ends of the pipe.
0
 

Author Comment

by:thordk
Comment Utility
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
Comment Utility
That appeared to have solved my problem ! thanks alot.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now