Mutex Permissions

G

Guest

I want to set a mutex in one windows account and allow another windows account to access this mutex.

For testing I have two forms that create a mutex using the C# mutex class. I am logging into Windows XP as "User1" and creating and locking the mutex from "User1" using the 1st form. I then use the "switch users" function to log in as "User2" and run the 2nd form and attempt to create the mutex (using the same name). When I try this I get access denied.

I have then tried to use the Win32 classes (as below) but still not working (same problem "access denied"). Any ideas?

namespace MyWin32API
{

// Required SecurityAttributes Structure LPSECURITY_ATTRIBUTES
[StructLayout(LayoutKind.Sequential)]
public class SecurityAttributes
{
public int nLength = Marshal.SizeOf(typeof(SecurityAttributes));
public long lpSecurityDescriptor;
public bool bInheritHandle;
}
public class CWin32
{

// Security Rights Constants - See Winnt.h
public const UInt32 SYNCHRONIZE = 0x00100000;
public const UInt32 STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const UInt32 MUTANT_QUERY_STATE = 0x0001;

// Security Rights Constants - See winbase.h and winnt.h
public static UInt32 MUTEX_ALL_ACCESS = (SYNCHRONIZE |
STANDARD_RIGHTS_REQUIRED | MUTANT_QUERY_STATE);
//CreateMutex
[DllImport("kernel32.dll", SetLastError=true)]
private static extern UInt32 CreateMutex(SecurityAttributes
lpMutexAttributes, bool InitialOwner, string MutexName);

// Win 32 Masked Method - does not use return handle currently
public UInt32 Win32CreateMutex(bool InitialOwner, string MutexName)
{
SecurityAttributes sa = new SecurityAttributes();
sa.bInheritHandle = false;
sa.lpSecurityDescriptor = CWin32.MUTEX_ALL_ACCESS;

return CWin32.CreateMutex(sa,InitialOwner,MutexName);
}
}

Thank you,

Kris
 
W

Willy Denoyette [MVP]

You need to create a DACL containing an ACE's for all trustee's you want to
access the Mutex object, and set the DACL's address in the
SecurityAttributes lpSecurityDescriptor member.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top