Ask a Question related to ASP.NET Security, Design and Development.
-
Louis-Philippe Carignan #1
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);
}
Louis-Philippe Carignan Guest
-
CFFILE upload error - The process cannot access the filebecause it is being used by another process
I get this error intermitently when trying to upload a file. <cffile action='upload' ... To make sure there was nothing wrong with the file, i... -
#37998 [Asn->Fbk]: Parent process lost MySQLi connection after child process gone
ID: 37998 Updated by: tony2001@php.net Reported By: dbs at is dot ua -Status: Assigned +Status: ... -
Win32::Process, SetProcessAffinityMask for an existing process =perl crash
Hi! Was planning to use Win32::Process to set the ProcessAffinityMask of some processes but this lead to pure and simple crash of perl.exe. ... -
Calling a WS-Security web-service from ASP Application via ASP.NET or .NET Class using interop
I suppose using the Interop approach to get ASP page to call a .NET Class (via interop) to make the web-service call (as indicated at... -
Using Batch process to remove security, acrobat 6
Hello, I wasn't able to find anything on this in the FAQ or Top Problems, I was hoping someone here might be able to help. Does anyone know of a... -
Joe Kaplan \(MVP - ADSI\) #2
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);
>
> }
>
>
>
Joe Kaplan \(MVP - ADSI\) Guest
-
Louis-Philippe Carignan #3
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...think> 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. Ihow> there is a similar trick you can do with .NET remoting, but I'm not sureof> 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 beginningdomain> > 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 anotherdomain)> > and this domain doesn't trust my dev machine (which is in anothersatisfied> >
> > Currently, my only workaround is to comment the code. I am notwould> > with this behavior. I though of going throught the Win32 API but Ithe> > 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 bypassprogram> > 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>> >
> > 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 Guest
-
Joe Kaplan \(MVP - ADSI\) #4
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...> think>> 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> how>> there is a similar trick you can do with .NET remoting, but I'm not sure> of>> 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> domain>> > 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> satisfied>> >
>> > Currently, my only workaround is to comment the code. I am not> would>> > with this behavior. I though of going throught the Win32 API but I> the>> > 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> program>> > 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>>>>> >
>> > 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\) Guest



Reply With Quote

