Opening .exe file inside of program

bL4cKh4T

Baseband Member
Messages
57
Location
Jacksonville, Fl
so i'm making this program to automate certain tasks. what I want to do is open an exe file inside of my program, i'm using c# btw. here is what I have:
Code:
System.Diagnostics.Process.Start("01.exe");
i made a button in visual studio and wrote this code for the button. this is set to open the file 01.exe in the same directory as the program but what I want to do is open it in a different directory than the program and I want my program to be able to point to the .exe file even if i move the program and folder that the exe file is in to a flash drive. the file is going to be in a folder called "files" and from the command prompt, i can get to the exe file in the files folder by typing ./files/01.exe but i don't know how to write that in the script. sorry if I am a little confusing. i'm still learning the language. thanks for any help you can give!
 
You should just be able to do
Process.Start("files\\01.exe")

As long as the 01.exe is always in a subdirectory of where the main program's EXE is, it should be fine (this would be a relative path).

You could also use the System.Reflection library to get the full, current running path of the main EXE, and go into the subdirectory that way (this would be an absolute path).
 
No problem - good to hear it worked.

For directories, if you're fully pathing it out manually (or including subdirectories like that), you need to use the \ character for the path. And in C#, for strings, you'll need to also escape certain special characters with the \ character...so that's why there's a \\ in the Proess.Start() method above.

You can get around that by creating a string literal, which simply means putting an @ sign in front of the string. So it could be like:

Process.Start(@"files\01.exe");
instead of
Process.Start("files\\01.exe");

Either way should work fine - just up to you on which you like better.
 
The @ definitely makes things more legible, especially when you're having a quick glance to see what's going on in what directory. I personally use it a lot when coding in C#, but that's just me.
 
Back
Top Bottom