Getting the name of my application at runtime...

  • Thread starter Thread starter beaker
  • Start date Start date
B

beaker

Hello,

Is there a way to get the name of my application (as it appears on the
list of processes running) at runtime?

(Something to do with System.Reflection...?)

Thanks,

Gary
 
Larry said:
Application.ProductName

Thanks for the reply, but I believe that only gives me the assembly name
(as filled in in my AssemblyInfo.cs), and not the name of the .exe -
which aren't neccessarily the same (I tried renaming my app to check).

Gary
 
beaker,

Task manager's Application tab shows the caption of the application's
top-level windows.
The process tab on the other hand shows the name of the executables. As long
as there are couple of ways you can get that I think the easises is to
extract the file name from
Application.ExecutablePath. To extract the file name only you can use the
Path.GetFileName.

I don't know about Application.ProductName. I personally have never used it,
but if you say that this is not what you want then try using
Application.ExecutablePath.

If you want to get reference to the executable file assembly you can use
Assembly.GetEntryAssembly static method.
 
beaker said:
Hello,

Is there a way to get the name of my application (as it appears on the
list of processes running) at runtime?

(Something to do with System.Reflection...?)

Thanks,

Gary



Thanks,

Process.GetCurrentProcess().ProcessName

and

Path.GetFileNameWithoutExtension(Application.ExecutablePath)

both worked fine.

I was working on a way of stopping multiple instances of my program
running, so wanted to check my app against a list of running process
(allowing for the .exe having been renamed from the original).
Of course, this all falls down if different copies of my program exist
with different names, but I can live with that for the moment.

Cheers,

Gary
 

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

Back
Top