473,657 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with named mutex shared between asp.net and .net win app.

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
executable creates the named mutex, then the asp.net application cannot
access it.

I know that in MFC you can set a security descriptor for the CMutex object
so that it is created with a set security descriptor level. How is this
done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Jul 21 '05 #1
5 3787
pick one, maybe the asp.net account. and set it to impersonate the same
account the windows app uses. better yet, create a single user account and
have both these applications impersonate this user to create and access the
mutex.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Ken Varn" <nospam> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
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
executable creates the named mutex, then the asp.net application cannot
access it.

I know that in MFC you can set a security descriptor for the CMutex object
so that it is created with a set security descriptor level. How is this
done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Jul 21 '05 #2
Sorry, this is not an area I am real familiar with in .NET. I know that in
MFC, I cam create a mutex object with SECURITY_ATTRIB UTES and thus indicate
the security level of the mutex. I am not sure how to do the same thing in
..NET. All I want to do is grant all processes access to this mutex without
doing impersonation. Is this possible?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:uG******** *******@TK2MSFT NGP12.phx.gbl.. .
pick one, maybe the asp.net account. and set it to impersonate the same
account the windows app uses. better yet, create a single user account and
have both these applications impersonate this user to create and access the mutex.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Ken Varn" <nospam> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
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
executable creates the named mutex, then the asp.net application cannot
access it.

I know that in MFC you can set a security descriptor for the CMutex object so that it is created with a set security descriptor level. How is this
done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------


Jul 21 '05 #3
Bellow is the snippet of the code that either opens already created mutex or
creates one that can be open by any process.
The trick here is to set right security attributes for newly created mutex.
Some of the functions used are from native Win32 API - you will need to map
them to your program.
Let me know if you have problems doing so.
private void PrivateConstruc t(bool initiallyOwned, string name, out
bool createdNew)
{
// It's faster to first try OpenMutex
int hMutex = OpenMutex(SYNCH RONIZE, 1, ToSystemMutexNa me(name));
createdNew = false;
if (hMutex == 0)
{
SECURITY_ATTRIB UTES sa = new SECURITY_ATTRIB UTES();
sa.nLength =
System.Runtime. InteropServices .Marshal.SizeOf (sa);
sa.bInheritHand le = 1;
sa.lpSecurityDe scriptor = 0;

int securityDescrip torSize = 0; // dummy
int result =
ConvertStringSe curityDescripto rToSecurityDesc riptor(
"D:(A;NP;0x001f 0001;;;WD)", // Grant
MUTEX_ALL_ACCES S to Everyone
SDDL_REVISION_1 ,
ref sa.lpSecurityDe scriptor,
ref securityDescrip torSize);
if (result == 0)
{
throw new Exception("Fail ure while creating security
descriptor for new mutex");
}

hMutex = CreateMutex(ref sa, initiallyOwned ? 1 : 0,
ToSystemMutexNa me(name));
createdNew = (Marshal.GetLas tWin32Error() !=
ERROR_ALREADY_E XISTS);
LocalFree(sa.lp SecurityDescrip tor);

if (hMutex == 0)
{
// If we get here, some sort of unrecoverable error has
presumably occurred.
// However, we will try one last time, in case it was
merely some sort of race condition.
// Note that I do not believe that there is any opening
for a race condition in the above code.
// Nevertheless, we have nothing to lose by giving it
one last try.
hMutex = OpenMutex(SYNCH RONIZE, 1,
ToSystemMutexNa me(name));
createdNew = false;
if (hMutex == 0)
{
throw new Exception("Unab le to create or open
mutex.");
}
}
}

Handle = (IntPtr)hMutex;
}
Sergiy Mesropyan
www.anticipatingminds.com


"Ken Varn" <nospam> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
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
executable creates the named mutex, then the asp.net application cannot
access it.

I know that in MFC you can set a security descriptor for the CMutex object
so that it is created with a set security descriptor level. How is this
done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Jul 21 '05 #4
It sounds as if there is no way to do this in native .NET code without using
pinvoke. Seems odd that this functionality was not included in the Mutex
object since this is part of the Win32 Mutex capability.

My module is in managed C++, but I was using the .NET version of Mutex just
to limit the amount of mixed code that I was using. I guess I can go back
and use the Win32 calls directory in my managed C++ code. It is a little
frustrating when some of these basic Win32 features are not included in
managed classes that appear to mimic the Win32 functionality.

Also, as a side note, I can't even understand why the ASP.NET application
would prevent the Windows application from accessing the mutex that it
created since the windows app was running as an administrator level.
--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
"Sergiy Mesropyan" <no****@nospam. com> wrote in message
news:Gv******** ************@co mcast.com...
Bellow is the snippet of the code that either opens already created mutex or creates one that can be open by any process.
The trick here is to set right security attributes for newly created mutex. Some of the functions used are from native Win32 API - you will need to map them to your program.
Let me know if you have problems doing so.
private void PrivateConstruc t(bool initiallyOwned, string name, out bool createdNew)
{
// It's faster to first try OpenMutex
int hMutex = OpenMutex(SYNCH RONIZE, 1, ToSystemMutexNa me(name)); createdNew = false;
if (hMutex == 0)
{
SECURITY_ATTRIB UTES sa = new SECURITY_ATTRIB UTES();
sa.nLength =
System.Runtime. InteropServices .Marshal.SizeOf (sa);
sa.bInheritHand le = 1;
sa.lpSecurityDe scriptor = 0;

int securityDescrip torSize = 0; // dummy
int result =
ConvertStringSe curityDescripto rToSecurityDesc riptor(
"D:(A;NP;0x001f 0001;;;WD)", // Grant
MUTEX_ALL_ACCES S to Everyone
SDDL_REVISION_1 ,
ref sa.lpSecurityDe scriptor,
ref securityDescrip torSize);
if (result == 0)
{
throw new Exception("Fail ure while creating security
descriptor for new mutex");
}

hMutex = CreateMutex(ref sa, initiallyOwned ? 1 : 0,
ToSystemMutexNa me(name));
createdNew = (Marshal.GetLas tWin32Error() !=
ERROR_ALREADY_E XISTS);
LocalFree(sa.lp SecurityDescrip tor);

if (hMutex == 0)
{
// If we get here, some sort of unrecoverable error has presumably occurred.
// However, we will try one last time, in case it was
merely some sort of race condition.
// Note that I do not believe that there is any opening for a race condition in the above code.
// Nevertheless, we have nothing to lose by giving it
one last try.
hMutex = OpenMutex(SYNCH RONIZE, 1,
ToSystemMutexNa me(name));
createdNew = false;
if (hMutex == 0)
{
throw new Exception("Unab le to create or open
mutex.");
}
}
}

Handle = (IntPtr)hMutex;
}
Sergiy Mesropyan
www.anticipatingminds.com


"Ken Varn" <nospam> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
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
executable creates the named mutex, then the asp.net application cannot
access it.

I know that in MFC you can set a security descriptor for the CMutex object so that it is created with a set security descriptor level. How is this
done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------


Jul 21 '05 #5
There is basically no support for Windows security in .NET 1.x except for
the WindowsIdentity and WindowsPrincipa l classes. Thus, any time you need
to do something with SDs, DACLs, ACEs, SIDs and tokens, you end up doing
interop and pinvoke. Thus the proliferation of wrappers to fill the gap.

The Whidbey story is better though. Also greatly improved is crypto support
which needed a lot of help too.

Joe K.

"Ken Varn" <nospam> wrote in message
news:eo******** ******@tk2msftn gp13.phx.gbl...
It sounds as if there is no way to do this in native .NET code without using pinvoke. Seems odd that this functionality was not included in the Mutex
object since this is part of the Win32 Mutex capability.

My module is in managed C++, but I was using the .NET version of Mutex just to limit the amount of mixed code that I was using. I guess I can go back
and use the Win32 calls directory in my managed C++ code. It is a little
frustrating when some of these basic Win32 features are not included in
managed classes that appear to mimic the Win32 functionality.

Also, as a side note, I can't even understand why the ASP.NET application
would prevent the Windows application from accessing the mutex that it
created since the windows app was running as an administrator level.
--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
"Sergiy Mesropyan" <no****@nospam. com> wrote in message
news:Gv******** ************@co mcast.com...
Bellow is the snippet of the code that either opens already created mutex
or
creates one that can be open by any process.
The trick here is to set right security attributes for newly created

mutex.
Some of the functions used are from native Win32 API - you will need to

map
them to your program.
Let me know if you have problems doing so.
private void PrivateConstruc t(bool initiallyOwned, string name,

out
bool createdNew)
{
// It's faster to first try OpenMutex
int hMutex = OpenMutex(SYNCH RONIZE, 1,

ToSystemMutexNa me(name));
createdNew = false;
if (hMutex == 0)
{
SECURITY_ATTRIB UTES sa = new SECURITY_ATTRIB UTES();
sa.nLength =
System.Runtime. InteropServices .Marshal.SizeOf (sa);
sa.bInheritHand le = 1;
sa.lpSecurityDe scriptor = 0;

int securityDescrip torSize = 0; // dummy
int result =
ConvertStringSe curityDescripto rToSecurityDesc riptor(
"D:(A;NP;0x001f 0001;;;WD)", // Grant
MUTEX_ALL_ACCES S to Everyone
SDDL_REVISION_1 ,
ref sa.lpSecurityDe scriptor,
ref securityDescrip torSize);
if (result == 0)
{
throw new Exception("Fail ure while creating security
descriptor for new mutex");
}

hMutex = CreateMutex(ref sa, initiallyOwned ? 1 : 0,
ToSystemMutexNa me(name));
createdNew = (Marshal.GetLas tWin32Error() !=
ERROR_ALREADY_E XISTS);
LocalFree(sa.lp SecurityDescrip tor);

if (hMutex == 0)
{
// If we get here, some sort of unrecoverable error

has
presumably occurred.
// However, we will try one last time, in case it was merely some sort of race condition.
// Note that I do not believe that there is any

opening
for a race condition in the above code.
// Nevertheless, we have nothing to lose by giving it one last try.
hMutex = OpenMutex(SYNCH RONIZE, 1,
ToSystemMutexNa me(name));
createdNew = false;
if (hMutex == 0)
{
throw new Exception("Unab le to create or open
mutex.");
}
}
}

Handle = (IntPtr)hMutex;
}
Sergiy Mesropyan
www.anticipatingminds.com


"Ken Varn" <nospam> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
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
executable creates the named mutex, then the asp.net application
cannot access it.

I know that in MFC you can set a security descriptor for the CMutex

object so that it is created with a set security descriptor level. How is this done in .NET using .NET mutex object?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------



Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4393
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
0
2195
by: trayguy | last post by:
Accepting the fact that .NET 1.x is lacking support for named events, and windows security manipulation, we end up using interop and the platform SDK, and functions like CreateMutex and OpenMutex. And it's with OpenMutex that I'm having a problem. In summary: I'm creating a mutex and then trying to 'open' it. I always get ERROR_ACCESS_DENIED which seems odd as the same process just created it moments before. This example is actually a...
16
3147
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
1
1612
by: k a | last post by:
Hello NG I'm using a named mutex to protect shared data between 3 processes. I've noticed that each process that waits for the mutex uses 50% of CPU usage... Can someone tell me what to do to minimize the CPU usage in the waiting processes? thanks patrice
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
1194
by: aB£ | last post by:
Hello all, I have an application which will seek the sql server table whether it is updated or not. This application runs once in 60 seconds. But the sql server table doesnt get updated frequently. So I thought of a logic where in the global.asax of my web application im invoking a semapore whenever any request comes.
7
368
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...
1
2054
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
3
4951
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
0
8303
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
8723
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
8502
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
8602
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
7316
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...
1
6162
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1941
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.