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 the exe path

Getting the exe path

Scheduled Pinned Locked Moved C#
csharptutorialquestion
8 Posts 6 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
    SatyaDY
    wrote on last edited by
    #1

    Hi, Can we get the exe path using C# calls?? I am getting only the special folders path, (like program files, programs, etc). How to get the user created folder paths?? Thanks and Regards, Satya Prasad :)

    P S 2 Replies Last reply
    0
    • S SatyaDY

      Hi, Can we get the exe path using C# calls?? I am getting only the special folders path, (like program files, programs, etc). How to get the user created folder paths?? Thanks and Regards, Satya Prasad :)

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

      Application.StartupPath ?

      S 1 Reply Last reply
      0
      • P partyganger

        Application.StartupPath ?

        S Offline
        S Offline
        SatyaDY
        wrote on last edited by
        #3

        Hi, I have started the application like this in a Service called myservice. Process myapp=Process.Start("application path"); Now I want to get the application path (which is hard coded) through the program. With myapp how to find out the path of the exe. Regards, Satya Prasad :)

        H 1 Reply Last reply
        0
        • S SatyaDY

          Hi, I have started the application like this in a Service called myservice. Process myapp=Process.Start("application path"); Now I want to get the application path (which is hard coded) through the program. With myapp how to find out the path of the exe. Regards, Satya Prasad :)

          H Offline
          H Offline
          hazzem elrefai
          wrote on last edited by
          #4

          System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.FileName=Environment.CurrentDirectory+"\\myexe.exe"; proc.StartInfo.Arguments=myargumentstring; //if u have arguments proc.Start();

          S 1 Reply Last reply
          0
          • H hazzem elrefai

            System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.FileName=Environment.CurrentDirectory+"\\myexe.exe"; proc.StartInfo.Arguments=myargumentstring; //if u have arguments proc.Start();

            S Offline
            S Offline
            SatyaDY
            wrote on last edited by
            #5

            Hi, Sorry I think my question is not clear. I have some process which starts some exe's. Now I am hard coding those exe's names. What I want the program should get the complete path of the exe and start those exe. Because these exe can be installed anywhere, If I hard code it creates problem. As you said Environment.CurrenDirectory it gives only the process's current directory not the exe's directory which I want to start. Is there any way to get that path of exe. Thanks and Regards, Satya Prasad. :)

            D H 2 Replies Last reply
            0
            • S SatyaDY

              Hi, Sorry I think my question is not clear. I have some process which starts some exe's. Now I am hard coding those exe's names. What I want the program should get the complete path of the exe and start those exe. Because these exe can be installed anywhere, If I hard code it creates problem. As you said Environment.CurrenDirectory it gives only the process's current directory not the exe's directory which I want to start. Is there any way to get that path of exe. Thanks and Regards, Satya Prasad. :)

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              SatyaDY wrote: Sorry I think my question is not clear No kidding.... SatyaDY wrote: Because these exe can be installed anywhere, If I hard code it creates problem. You need some way of determining where those .EXE's are? Did you install them as part of your package? If so, then you could generate an .INI file listing the locations of the .EXE's. Your service could then read that .INI file to get the path to the .EXE's you want to launch. If not, your going to have to come up with a way to find these .EXE's and create an .INI file that can be used by your service. Possibly asking the user where they are? Or writing code to hunt them down? It's up to you... Another method, although less reliable and surely more problematic, would be to write code that searches the drive for the .EXE names you want, then launch them. I think you can see the security and reliability problems with that approach... RageInTheMachine9532

              1 Reply Last reply
              0
              • S SatyaDY

                Hi, Sorry I think my question is not clear. I have some process which starts some exe's. Now I am hard coding those exe's names. What I want the program should get the complete path of the exe and start those exe. Because these exe can be installed anywhere, If I hard code it creates problem. As you said Environment.CurrenDirectory it gives only the process's current directory not the exe's directory which I want to start. Is there any way to get that path of exe. Thanks and Regards, Satya Prasad. :)

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                When executables are in directories listed in the PATH environment variable, they can be executed without specify a directory. If they aren't in the path (including the current working directory), then you need to know where they are up-front like Dave said. If the executable is in the PATH and you still want the full path, use Environment.GetEnvironmentVariable for "PATH", then use String.Split to split the paths into a string[] array using ";" as the delimiter. You can then search those paths in order to find all the paths to the executables. If they aren't in the PATH, then you should either store the paths in the registry or some common file during installation, or creating an RCW (Runtime Callable Wrapper) around the MSI runtime (if you used Windows Installer for your installation of these programs) and query for the executable's component path. There's no automagical way to get this information.

                Microsoft MVP, Visual C# My Articles

                1 Reply Last reply
                0
                • S SatyaDY

                  Hi, Can we get the exe path using C# calls?? I am getting only the special folders path, (like program files, programs, etc). How to get the user created folder paths?? Thanks and Regards, Satya Prasad :)

                  S Offline
                  S Offline
                  Sascha Andres
                  wrote on last edited by
                  #8

                  Hi, since now I used sonething like this:

                  System.IO.FileInfo fi = new System.IO.FileInfo(Application.ExecutablePath);
                  GlobalContainer.ExecutablePath = fi.DirectoryName;
                  fi = null;

                  Help states: Property Value The path and executable name for the executable file that started the application. Caveeat: You need to reference System.Windows.Forms. -sa -- http://www.livingit.de http://www.mobile-bookmarks.info http://www.not2long.net

                  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