Getting An "Access Is Denied" Error When Opening A MailSlot Created By Another User

Posted on 2006-04-06
Last Modified: 2010-05-19
We have a VB6 app that creates a mailslot, and we have a VB.NET service that writes to the mailslot. When the two run as the same user, or if the service runs as the LocalSystemAccount, everything works fine. But if I have the service run as another user, even if the user has Admin privileges, the service gets an "Access Is Denied" error when opening the mailslot.

I can't find any info on setting a mailslot's access level.

VB6 Code:
    sa.bInheritHandle = True
    sa.lpSecurityDescriptor = 0
    sa.nLength = Len(sa)
    hMailSlot = CreateMailslot("\\.\mailslot\uniquemailslotname", Len(mm), 0, sa)

                sa.nLength = Len(sa)
                sa.bInheritHandle = True
                mHandle = New IntPtr(CreateFile("\\.\mailslot\uniquemailslotname", _
                                    GENERIC_READ Or GENERIC_WRITE, _
                                    FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                                    sa, _
                                    OPEN_EXISTING, _
                                    FILE_ATTRIBUTE_NORMAL, _

    mHandle.ToInt32 will equal INVALID_HANDLE_VALUE
    Calling FormatMessage(Marshal.GetLastWin32Error)) returns "Access is denied."

Any help is appreciated!
Question by:sgutmann

    Author Comment

    Solved my own problem...

    Turns out there are a few workarounds:
    1. Simply use the computer name instead of a . and that forces the mailslot to grant access to everyone.
    2. Set the security descriptor (sa.lpSecurityDescriptor) to a DACL with the proper read/write acccess.

    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now