472,139 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Mutex Permissions

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
Nov 16 '05 #1
2 6874
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.

"Kris" <an*******@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
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

Nov 16 '05 #2
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.

"Kris" <an*******@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Srijit Kumar Bhadra | last post: by
2 posts views Thread by Martin Maat | last post: by
1 post views Thread by Kris | last post: by
reply views Thread by William LaMartin | last post: by
2 posts views Thread by William LaMartin | last post: by
2 posts views Thread by tony.newsgrps | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.