• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 952
  • Last Modified:

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:
    Dim sa As SECURITY_ATTRIBUTES
    sa.bInheritHandle = True
    sa.lpSecurityDescriptor = 0
    sa.nLength = Len(sa)
    hMailSlot = CreateMailslot("\\.\mailslot\uniquemailslotname", Len(mm), 0, sa)

VB.NET:
                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, _
                                    0))

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

Any help is appreciated!
0
sgutmann
Asked:
sgutmann
1 Solution
 
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.
0
 
EE_AutoDeleterCommented:
sgutmann,
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.

EE_AutoDeleter
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now