Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting own filename

Getting own filename

Scheduled Pinned Locked Moved C#
question
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silvyster
    wrote on last edited by
    #1

    Is it possible to get the program's own filename on runtime?(exe file)

    P _ V 3 Replies Last reply
    0
    • S Silvyster

      Is it possible to get the program's own filename on runtime?(exe file)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Yes, of course. OK, here's what I use: System.Windows.Forms.Application.ExecutablePath and sometimes I pass that through System.IO.Path.GetFileNameWithoutExtension()

      modified on Thursday, January 22, 2009 10:40 PM

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Yes, of course. OK, here's what I use: System.Windows.Forms.Application.ExecutablePath and sometimes I pass that through System.IO.Path.GetFileNameWithoutExtension()

        modified on Thursday, January 22, 2009 10:40 PM

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        PIEBALDconsult wrote:

        Yes, of course.

        :laugh:

        Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns

        1 Reply Last reply
        0
        • S Silvyster

          Is it possible to get the program's own filename on runtime?(exe file)

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          Get the current process using Process.GetCurrentProcess() Then use the ProcessName or MainModule property.

          «_Superman_»

          P 1 Reply Last reply
          0
          • _ _Superman_

            Get the current process using Process.GetCurrentProcess() Then use the ProcessName or MainModule property.

            «_Superman_»

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I don't think that'll work reliably.

            _ 1 Reply Last reply
            0
            • P PIEBALDconsult

              I don't think that'll work reliably.

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              You mean, we would not always get the filename ?

              «_Superman_»

              P 1 Reply Last reply
              0
              • S Silvyster

                Is it possible to get the program's own filename on runtime?(exe file)

                V Offline
                V Offline
                vaghelabhavesh
                wrote on last edited by
                #7

                You can use Assembly.GetExecutingAssembly().GetName() in .Net and if you want file path then you can use this one[^]

                P 1 Reply Last reply
                0
                • _ _Superman_

                  You mean, we would not always get the filename ?

                  «_Superman_»

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Is there a guarantee that the process name is the filename? On the other hand I just tried it and it seems to be reliable. At least it knows if I change the file name. I may need to look into it further.

                  _ 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Is there a guarantee that the process name is the filename? On the other hand I just tried it and it seems to be reliable. At least it knows if I change the file name. I may need to look into it further.

                    _ Offline
                    _ Offline
                    _Superman_
                    wrote on last edited by
                    #9

                    I guess you might as well you the GetModuleFileName API

                    «_Superman_»

                    P 1 Reply Last reply
                    0
                    • V vaghelabhavesh

                      You can use Assembly.GetExecutingAssembly().GetName() in .Net and if you want file path then you can use this one[^]

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #10

                      If main calls a library routine in another assembly and that routine does that, you'll get the name of the library assembly, not the assembly containing main.

                      1 Reply Last reply
                      0
                      • _ _Superman_

                        I guess you might as well you the GetModuleFileName API

                        «_Superman_»

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #11

                        That may have a problem if called from a different assembly? I guess stick with System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName. I suppose might System.Windows.Forms.Application.ExecutablePath call that.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups