Getting the exe path
-
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 :)
Application.StartupPath ?
-
Application.StartupPath ?
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 :)
-
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 :)
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();
-
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();
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. :)
-
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. :)
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
-
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. :)
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 useString.Split
to split the paths into astring[]
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
-
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 :)
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