How does one get the application name of a C# program at runtime


  1.    05 Aug 2008 #1
    Andrew Falanga Guest

    How does one get the application name of a C# program at runtime


    Hi,

    How do I get the application name during run time. In C or C++ I use
    argv[0], but in C# args[0] contains the first argument to the program
    not the program name. So, what is the magic to getting this?

    Thanks,
    Andy
      My System SpecsSystem Spec

  2.    05 Aug 2008 #2
    Jeroen Mostert Guest

    Re: How does one get the application name of a C# program at runtime


    Andrew Falanga wrote:

    > How do I get the application name during run time. In C or C++ I use
    > argv[0], but in C# args[0] contains the first argument to the program
    > not the program name. So, what is the magic to getting this?
    >
    Environment.GetCommandLineArgs().

    --
    J.
      My System SpecsSystem Spec

  3.    05 Aug 2008 #3
    Jon Skeet [C# MVP] Guest

    Re: How does one get the application name of a C# program at runtime


    Andrew Falanga <af300wsm@xxxxxx> wrote:

    > How do I get the application name during run time. In C or C++ I use
    > argv[0], but in C# args[0] contains the first argument to the program
    > not the program name. So, what is the magic to getting this?
    You can use Application.ExecutablePath - it's in System.Windows.Forms,
    but it works for console apps too.

    --
    Jon Skeet - <skeet@xxxxxx>
    Web site: http://www.pobox.com/~skeet
    Blog: http://www.msmvps.com/jon.skeet
    C# in Depth: http://csharpindepth.com
      My System SpecsSystem Spec

  4.    05 Aug 2008 #4
    Mark Salsbery [MVP] Guest

    Re: How does one get the application name of a C# program at runtime



    "Andrew Falanga" <af300wsm@xxxxxx> wrote in message
    news:27a7bd0f-b021-47b4-bafe-f106c78dd51b@xxxxxx

    > Hi,
    >
    > How do I get the application name during run time. In C or C++ I use
    > argv[0], but in C# args[0] contains the first argument to the program
    > not the program name. So, what is the magic to getting this?

    There may be an easier way, but this works:

    String thismodulefilenamestr =
    System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

    Mark

    --
    Mark Salsbery
    Microsoft MVP - Visual C++



    >
    > Thanks,
    > Andy
      My System SpecsSystem Spec

  5.    05 Aug 2008 #5
    Mark Salsbery [MVP] Guest

    Re: How does one get the application name of a C# program at runtime


    "Andrew Falanga" <af300wsm@xxxxxx> wrote in message
    news:27a7bd0f-b021-47b4-bafe-f106c78dd51b@xxxxxx

    > Hi,
    >
    > How do I get the application name during run time. In C or C++ I use
    > argv[0], but in C# args[0] contains the first argument to the program
    > not the program name. So, what is the magic to getting this?

    Here's another one

    String thismodulefilenamestr =
    System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);

    Mark

    --
    Mark Salsbery
    Microsoft MVP - Visual C++


    >
    > Thanks,
    > Andy
      My System SpecsSystem Spec

  6.    05 Aug 2008 #6
    Alun Harford Guest

    Re: How does one get the application name of a C# program at runtime


    Jon Skeet [C# MVP] wrote:

    > Andrew Falanga <af300wsm@xxxxxx> wrote:

    >> How do I get the application name during run time. In C or C++ I use
    >> argv[0], but in C# args[0] contains the first argument to the program
    >> not the program name. So, what is the magic to getting this?
    >
    > You can use Application.ExecutablePath - it's in System.Windows.Forms,
    > but it works for console apps too.
    Or if you really want, you can use:

    new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath

    (Application.ExecutablePath is much easier though)

    Alun Harford
      My System SpecsSystem Spec

How does one get the application name of a C# program at runtime

Similar Threads
Thread Forum
32bit application compiles in 64bit mode but errors in runtime
I have two C++ applications that was originally written for 32bit systems using visual studio 2008 under windows xp, I am doing some research to...
.NET General
"This application has requested the Runtime to terminate it in an unusual way."
Microsoft Visual C++ Runtime Library Runtime Error! This application has requested the Runtime to terminate it in an unusual way. Please...
Vista performance & maintenance
Visual studio 2008 IDE application R6034 runtime error - MSDN news group moderator Please Respond.
I am getting a Visual studio 2008 IDE application R6034 runtime error. This means that the IDE application is raising the error not the application...
.NET General
Runtime Error (abnormal program termination)
I have purchased an HP officejet 5610 all-in-one, installed it, So far no problem. Scanned a picture using the icon on the desktop no problem from...
General Discussion
runtime error 2147221018 (800-401e6) No program registered toopen
Since moving from XP to Vista I have several Excel files that won't launch hyperlinks to wav. files - error message is (runtime error '-2147221018...
Vista General
application causing runtime error
I keep getting the same runtime error popup. Program: C:\Program Files\HP\hpcoretech\comp\hptskmgr.exe This application has requested the...
Vista performance & maintenance
How to change Style at runtime in application-level
Hi~ I want to change the style of all controls in application which contains pages. In document, I can use Style in Application.Resource ...
Avalon

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • Old server
    About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 12:41.
    .