Mutex access denied

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

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
 
tshad said:
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.
 
Jeroen Mostert said:
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
 
Back
Top