473,770 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mutex access denied

I am running a program as a Windows service which works fine.

I am using a Mutex to prevent multiple threads from from accessing my log
text file at the same time. It works fine in the Service:

In my AppSettings class:

public static Mutex mutexPrinterFil e;

In my program:

AppSettings.mut exPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mut exPrinterFile.W aitOne();

When I run this program as a Windows program (same code) - I get an Access
Denied error.

I also using impersonation to allow me to move my files to another folder on
another server. Inside the Impersonation code is where I am having the
problem.

How would I change this to allow me to work with my logon credentials or the
impersonation credentials?

Obviously, it has no problem when running as a Windows Service and the
Impersonation credentials.

Thanks,

Tom

Nov 13 '08 #1
2 4868
tshad wrote:
I am running a program as a Windows service which works fine.

I am using a Mutex to prevent multiple threads from from accessing my log
text file at the same time. It works fine in the Service:

In my AppSettings class:

public static Mutex mutexPrinterFil e;

In my program:

AppSettings.mut exPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mut exPrinterFile.W aitOne();

When I run this program as a Windows program (same code) - I get an Access
Denied error.

I also using impersonation to allow me to move my files to another folder on
another server. Inside the Impersonation code is where I am having the
problem.
A named mutex is for interprocess synchronization . Do you actually need the
mutex for interprocess synchronization or is it sufficient for the threads
within your process to have exclusive access? If the latter, creating the
mutex as a nameless object would do the trick.

Otherwise, try opening the mutex first with .OpenExisting() , specifying
MutexRights.Syn chronize. Create a new mutex only if this call fails.

If this doesn't work either, you'll need to be more specific with the access
rights of the mutex and specifically grant the credentials that will need to
access the mutex rights. Take a look at the MutexAccessRule class.

--
J.
Nov 14 '08 #2

"Jeroen Mostert" <jm******@xs4al l.nlwrote in message
news:49******** *************@n ews.xs4all.nl.. .
tshad wrote:
>I am running a program as a Windows service which works fine.

I am using a Mutex to prevent multiple threads from from accessing my log
text file at the same time. It works fine in the Service:

In my AppSettings class:

public static Mutex mutexPrinterFil e;

In my program:

AppSettings.mut exPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mut exPrinterFile.W aitOne();

When I run this program as a Windows program (same code) - I get an
Access Denied error.

I also using impersonation to allow me to move my files to another folder
on another server. Inside the Impersonation code is where I am having
the problem.
A named mutex is for interprocess synchronization . Do you actually need
the mutex for interprocess synchronization or is it sufficient for the
threads within your process to have exclusive access? If the latter,
creating the mutex as a nameless object would do the trick.

Otherwise, try opening the mutex first with .OpenExisting() , specifying
MutexRights.Syn chronize. Create a new mutex only if this call fails.

If this doesn't work either, you'll need to be more specific with the
access rights of the mutex and specifically grant the credentials that
will need to access the mutex rights. Take a look at the MutexAccessRule
class.
I will.

Thanks,

Tom
--
J.

Nov 20 '08 #3

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

Similar topics

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...
1
1939
by: gaiv | last post by:
I have a dll that creates a named mutex. The mutex is successfully created when loading the dll through a console application. However the same fails when running it though a Windows service. The service is running under the local system account. Thanks.
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
3370
by: mfdatsw1 | last post by:
I need to be certain my application only runs once on a machine, and I implemented a solution using Mutex. The solution was posted many times, but one great link I found is http://www.yoda.arachsys.com/csharp/faq/#one.application.instance The problem is, when I switch users (XP Professional) the second user can open a second instance of the application! How can I prevent this? Here's the relevant part of my code:
7
7064
by: UJ | last post by:
Has anybody seen an 'Access denied' error when trying to create a mutex? If so - what does that mean? I though Mutex's were not supposed to error out. TIA - Jeff.
0
1268
by: vishalshah3584 | last post by:
Hi All, I have developed two application. One is windows service and another is windows application using c# .net. I used Mutex for synchronization purpose. Now, my problem is application is working fine under Admin account but, I have a problem of accessing mutex under non-admin(Power User or restricted user) account. I got the following error: Constructor: Access to the path 'Config' is denied.
0
9618
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
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
8933
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
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...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
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.