Process class and .NET security

  • Thread starter Louis-Philippe Carignan
  • Start date
L

Louis-Philippe Carignan

Hi all,

I posted this message a couple of days ago on
microsoft.public.dotnet.framework and never got a response. I am trying
here because it involves security but it's not ASP. If someone has a better
idea where this post should go, please let met know.

Here is my problem:

I am using the Process class in my application, right at the beginning of
the static Main method. I am using the Process class to know if another
instance of my application is currently running. If my application is
already running, I will exit.

This works fine on my development machine. But if I run it on a deployment
machine, I get the error "Common Language Runtime Debugging Services :
Application has generated an exception that could not be handled". I cannot
run the remote debugger since the application is running in another domain
and this domain doesn't trust my dev machine (which is in another domain)

Currently, my only workaround is to comment the code. I am not satisfied
with this behavior. I though of going throught the Win32 API but I would
prefer a .NET solution to my problem. I know the problem is with the
Process class. In the .NET SDK documentation, there is 2 lines of text
about a permission used to access the Process class. How do I bypass the
security? How do I give the required permission to my application?

Thank you,

Louis-Philippe


Here is the code commented out

// Before starting the application, check if the same application

// is already running. If so, show a message box to the user

// indicating that the application is already running and exit the program

try

{

Process currentProcess = Process.GetCurrentProcess();

foreach (Process process in
Process.GetProcessesByName(currentProcess.ProcessName))

{

if (currentProcess.Id != process.Id)

{

LogManager.Log(typeof(ClientApp), APP_ERROR_TEXT, LogType.Error,
LogLevel.High);

MessageBox.Show(APP_ERROR_TEXT, APP_ERROR_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);

Shutdown();

return;

}

}

}

catch

{

LogManager.Log(typeof(ClientApp), APP_GETPROCESS_EXCEPTION_TEXT,
LogType.Error, LogLevel.High);

}
 
J

Joe Kaplan \(MVP - ADSI\)

Did you consider setting a Mutex (from System.Threading) in your start up
code and then check to see if that Mutex is held already in the same code?
The idea would be that if the mutex is already held, the application is
already running, so you would just exit or something.

You would then get rid of the mutex when you stop your program.

It doesn't solve your exact problem now, but it might work better. I think
there is a similar trick you can do with .NET remoting, but I'm not sure how
that works.

HTH,

Joe K.
 
L

Louis-Philippe Carignan

Thanks Joe for the advice. I didn't tought about the Mutex idea.

But I would still like to know why the Process class is giving me security
problems.
 
J

Joe Kaplan \(MVP - ADSI\)

I have no idea what was causing the error you were seeing, so I can't help
with that. Sorry!

Hopefully the mutex will work though.

Good luck,

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top