473,700 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SecurityAttribu tes Structure LPSECURITY_ATTR IBUTES
[StructLayout(La youtKind.Sequen tial)]
public class SecurityAttribu tes
{
public int nLength = Marshal.SizeOf( typeof(Security Attributes));
public long lpSecurityDescr iptor;
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_ST ATE = 0x0001;

// Security Rights Constants - See winbase.h and winnt.h
public static UInt32 MUTEX_ALL_ACCES S = (SYNCHRONIZE |
STANDARD_RIGHTS _REQUIRED | MUTANT_QUERY_ST ATE);
//CreateMutex
[DllImport("kern el32.dll", SetLastError=tr ue)]
private static extern UInt32 CreateMutex(Sec urityAttributes
lpMutexAttribut es, bool InitialOwner, string MutexName);

// Win 32 Masked Method - does not use return handle currently
public UInt32 Win32CreateMute x(bool InitialOwner, string MutexName)
{
SecurityAttribu tes sa = new SecurityAttribu tes();
sa.bInheritHand le = false;
sa.lpSecurityDe scriptor = CWin32.MUTEX_AL L_ACCESS;

return CWin32.CreateMu tex(sa,InitialO wner,MutexName) ;
}
}

Thank you,

Kris
Nov 16 '05 #1
2 7072
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
SecurityAttribu tes lpSecurityDescr iptor member.

Willy.

"Kris" <an*******@disc ussions.microso ft.com> wrote in message
news:F8******** *************** ***********@mic rosoft.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 SecurityAttribu tes Structure LPSECURITY_ATTR IBUTES
[StructLayout(La youtKind.Sequen tial)]
public class SecurityAttribu tes
{
public int nLength = Marshal.SizeOf( typeof(Security Attributes));
public long lpSecurityDescr iptor;
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_ST ATE = 0x0001;

// Security Rights Constants - See winbase.h and winnt.h
public static UInt32 MUTEX_ALL_ACCES S = (SYNCHRONIZE |
STANDARD_RIGHTS _REQUIRED | MUTANT_QUERY_ST ATE);
//CreateMutex
[DllImport("kern el32.dll", SetLastError=tr ue)]
private static extern UInt32 CreateMutex(Sec urityAttributes
lpMutexAttribut es, bool InitialOwner, string MutexName);

// Win 32 Masked Method - does not use return handle currently
public UInt32 Win32CreateMute x(bool InitialOwner, string MutexName)
{
SecurityAttribu tes sa = new SecurityAttribu tes();
sa.bInheritHand le = false;
sa.lpSecurityDe scriptor = CWin32.MUTEX_AL L_ACCESS;

return CWin32.CreateMu tex(sa,InitialO wner,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
SecurityAttribu tes lpSecurityDescr iptor member.

Willy.

"Kris" <an*******@disc ussions.microso ft.com> wrote in message
news:F8******** *************** ***********@mic rosoft.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 SecurityAttribu tes Structure LPSECURITY_ATTR IBUTES
[StructLayout(La youtKind.Sequen tial)]
public class SecurityAttribu tes
{
public int nLength = Marshal.SizeOf( typeof(Security Attributes));
public long lpSecurityDescr iptor;
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_ST ATE = 0x0001;

// Security Rights Constants - See winbase.h and winnt.h
public static UInt32 MUTEX_ALL_ACCES S = (SYNCHRONIZE |
STANDARD_RIGHTS _REQUIRED | MUTANT_QUERY_ST ATE);
//CreateMutex
[DllImport("kern el32.dll", SetLastError=tr ue)]
private static extern UInt32 CreateMutex(Sec urityAttributes
lpMutexAttribut es, bool InitialOwner, string MutexName);

// Win 32 Masked Method - does not use return handle currently
public UInt32 Win32CreateMute x(bool InitialOwner, string MutexName)
{
SecurityAttribu tes sa = new SecurityAttribu tes();
sa.bInheritHand le = false;
sa.lpSecurityDe scriptor = CWin32.MUTEX_AL L_ACCESS;

return CWin32.CreateMu tex(sa,InitialO wner,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
4403
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 SharedMemAccess_Mutex_ctypes.py or SharedMemAccess_Mutex_win32all.py
5
3797
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 application runs under the standard asp.net user account. The problem relates to permissions on creation of the mutex. If the asp.net application creates the mutex, the executable cannot access it (access denied error). Likewise, if the...
2
4775
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 Mutex mtxBezoeken = new Mutex(false, "bezoeken"); which compiles and executes just fine. Then in another page I want to write to a file that may also be accessed by global.asax.cs so I want access to
1
442
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 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...
16
3156
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 ownership, second did not and terminated. In a release build, the second instance *also* got ownership. I "fixed" it by making the mutex a static member of my MainForm class. Did the garbage collector eat my mutex because it is not referenced
0
1131
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 following error message on one server I host on.
2
3009
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 Shared FileLockMutex As System.Threading.Mutex Shared Sub New()
2
6229
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 { mutex=new System.Threading.Mutex( true, mutexName, out createdNew)
3
5573
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 the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
0
8728
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9217
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9076
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5903
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4659
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.