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

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!
Who is Participating?
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.

sgutmannAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.