473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 7015
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
2
by: Martin Maat | last post by:
Hi. I want to use the same mutex in different classes (web pages in an ASP.NET application). In global.asax.cs, the class that starts up first, I create a Mutex like this: static private...
1
by: Kris | last post by:
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...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
0
by: William LaMartin | last post by:
This code: Private Shared FileLockMutex As System.Threading.Mutex Shared Sub New() FileLockMutex = New System.Threading.Mutex(False, "MyFileLockMutex") End Sub on an aspx page produces the...
2
by: William LaMartin | last post by:
I posted this in the ASP.net newsgroup with no response, so I will try it here: What needs to be changes to make this work? It is on a Windows 2003 shared server. This code: Private...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.