473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 mutexPrinterFile;

In my program:

AppSettings.mutexPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mutexPrinterFile.WaitOne();

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 4799
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 mutexPrinterFile;

In my program:

AppSettings.mutexPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mutexPrinterFile.WaitOne();

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.Synchronize. 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******@xs4all.nlwrote in message
news:49*********************@news.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 mutexPrinterFile;

In my program:

AppSettings.mutexPrinterFile = new Mutex(false, "Repository
Printer Mutex");
AppSettings.mutexPrinterFile.WaitOne();

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.Synchronize. 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
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...
1
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...
2
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...
1
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...
16
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...
7
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.