Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Security (http://www.velocityreviews.com/forums/f62-asp-net-security.html)
-   -   Process class and .NET security (http://www.velocityreviews.com/forums/t766546-process-class-and-net-security.html)

Louis-Philippe Carignan 09-09-2004 02:10 PM

Process class and .NET security
 
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);

}




Joe Kaplan \(MVP - ADSI\) 09-09-2004 06:50 PM

Re: Process class and .NET security
 
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" <someone@somewhere.com> wrote in message
news:uiJl5anlEHA.3608@TK2MSFTNGP09.phx.gbl...
> 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);
>
> }
>
>
>




Louis-Philippe Carignan 09-10-2004 02:18 PM

Re: Process class and .NET security
 
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)" <joseph.e.kaplan@removethis.accenture.com> wrote
in message news:ehl8O3plEHA.3756@TK2MSFTNGP11.phx.gbl...
> 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" <someone@somewhere.com> wrote in message
> news:uiJl5anlEHA.3608@TK2MSFTNGP09.phx.gbl...
> > 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);
> >
> > }
> >
> >
> >

>
>




Joe Kaplan \(MVP - ADSI\) 09-10-2004 03:37 PM

Re: Process class and .NET security
 
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" <someone@somewhere.com> wrote in message
news:uUvU%23D0lEHA.2948@TK2MSFTNGP11.phx.gbl...
> 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)" <joseph.e.kaplan@removethis.accenture.com> wrote
> in message news:ehl8O3plEHA.3756@TK2MSFTNGP11.phx.gbl...
>> 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" <someone@somewhere.com> wrote in message
>> news:uiJl5anlEHA.3608@TK2MSFTNGP09.phx.gbl...
>> > 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);
>> >
>> > }
>> >
>> >
>> >

>>
>>

>
>





All times are GMT. The time now is 12:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.