Process class and .NET security

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. #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: ...
    3. 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. ...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

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

    Louis-Philippe Carignan Guest

  5. #4

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

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139