473,785 Members | 2,446 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 7080
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
4410
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
3804
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
4782
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
3163
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
1134
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
3013
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
6237
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
5595
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
9647
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
9491
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
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
9959
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
6744
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
5397
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
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.