Problem with Windows Mail slot mailslot client without access (GetLastError () = = 5) After establishing in the service program

Source: Internet
Author: User

Mail slots are created within the service program and can be created successfully,

But when the external client connects

M_hmailslot = CreateFile ("\\\\.\\mailslot\\zdpmailslot", Generic_write,file_share_read,null,open_existing,file_ Attribute_normal,null);
GetLastError return error 5, Access Denied not authorized

If the path changes to

\\\\*\\mailslot\\zdpmailslot

\\\\compername\\mailslot\\zdpmailslot

Can be connected successfully, but send a data service side to receive three times repeatedly, and the delay is huge (a few minutes). Confusing.

This article explains: guess the path is not the point then the remote call to go, each time to establish an authorization session, resulting in a huge delay

Http://www.360doc.cn/article/2660674_95457447.html

The lpSecurityAttributes parameter determines the access control permissions that are applied to the mail slot. In Windows NT and Windows2000, this parameter is only partially implemented, so you should also specify a null (empty) parameter. On the postal slot, the only security measure that can be applied is for local I/O----the client attempts to set the server's name to a decimal point (.) to open a mail slot. To circumvent this security mechanism, the client can specify the actual name of the server instead of a decimal, which is equivalent to issuing a remote I/O call. In Windows NT and Windows2000, the lpSecurityAttributes parameter is not implemented for remote I/O because if an authorization session is established between the client and the server each time a message is issued, the efficiency will be very low. As a result, only a subset of the postal slots conforms to the Windows NT and Windows2000 security models adopted by the standard file system. As a result, any mail slot client in the network can send data to the server.

= = = searched for half a day to find this online Article = =Permission issues for cross-process access to shared memory

http://m.blog.csdn.net/jiangsheng/article/details/25563

Using the CSHARERESTRICTEDSD class of Mr. Jiang to specify the custom security_attributes,

I don't know why this kind of writing is so complicated.

But put it in the service program when the Createmailslot is dead.

So give up

= = = Continue to search for half a day to find this online article StackOverflow foreigner's = ="Access Denied" on writing the mailslot in the Windows Service program

Https://stackoverflow.com/questions/8389549/access-denied-on-writing-on-mailslot-in-windows-service-program

A code for the specified security_attributes is given:

security_descriptor sd;initializesecuritydescriptor (&SD, security_descriptor_revision); SetSecurityDescriptorDacl (truefalse); Security_attributes sa;sa.lpsecuritydescriptor=&sd;sa.binherithandle=true; Phandlemailslot = Createmailslot ("your mail slot path"0,-1, & SA);

Make sure that the external connection is successful, but still the service program within the ReadFile receive giant slow, and there are regular, 1 minutes to receive a bar. To serve ...

Problem with Windows Mail slot mailslot client without access (GetLastError () = = 5) After establishing in the service program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.