473,770 Members | 2,136 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 7079
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
4408
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
4781
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
3161
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
6236
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
5594
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
9454
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
10260
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...
1
10038
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
9906
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...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
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
5354
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...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.