Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Process class and .NET security

Reply
Thread Tools

Process class and .NET security

 
 
Louis-Philippe Carignan
Guest
Posts: n/a
 
      09-09-2004
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.ProcessN ame))

{

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

}



 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      09-09-2004
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.

"Louis-Philippe Carignan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.ProcessN ame))
>
> {
>
> 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);
>
> }
>
>
>



 
Reply With Quote
 
 
 
 
Louis-Philippe Carignan
Guest
Posts: n/a
 
      09-10-2004
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.

"Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> 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.
>
> "Louis-Philippe Carignan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.ProcessN ame))
> >
> > {
> >
> > 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);
> >
> > }
> >
> >
> >

>
>



 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      09-10-2004
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.

"Louis-Philippe Carignan" <(E-Mail Removed)> wrote in message
news:uUvU%(E-Mail Removed)...
> 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.
>
> "Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
>> 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.
>>
>> "Louis-Philippe Carignan" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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.ProcessN ame))
>> >
>> > {
>> >
>> > 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);
>> >
>> > }
>> >
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
error using process module Process class Earl Eiland Python 0 05-10-2005 05:18 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
IT-Security, Security, e-security COMSOLIT Messmer Computer Support 0 09-05-2003 08:34 AM



Advertisments