Question starting an .exe process

val5662

New member
Joined
Oct 22, 2012
Messages
4
Programming Experience
Beginner
Hi All....
I am a beginner at writing code and I am trying to make a windows form application in the "SharpDevelop 4.2" program.
The program is very similar to "Visual Studio 10 Ultimate".
The program I am trying to make is a simple "click a button" to start a program ( Game exe ) on my C drive.
I Googled it and could not find the code I need.I am just stumped on one part of the code.
Here is where I need the correct code:
}

void Button2Click(object sender, EventArgs e)
{
//to start the application below,what goes in front of the ("C:\etc...etc...?
//and also is the ("C:\Sierra\Viper Racing\Viper Racing.exe");
// the correct way of starting the exe?
("C:\Sierra\Viper Racing\Viper Racing.exe");
//and is the Close code below correct to exit the form.exe after the button is clicked to start the Viper Racing.exe?
Close();

}
}
}

Note: "Process.start" does not exist in the options I have
also System.Diagnostics.Process.Start("C:\Sierra\Viper Racing\Viper Racing.exe"); will not work , but it does work to open internet explorer ("iexplore.exe");.
I appreciate any help you can give me.
Thanks!
Val
 
The reason that you can't use just 'Process.Start' is that you haven't imported the namespace it's a member of, i.e. System.Diagnostics. In order to use any type you must specify it's full name, either by fully qualifying it where you use it or by importing its namespace, which you do with a 'using' statement at the top of the code file. If you import System.Diagnostics then you can use the Process class unqualified.

When you call Process.Start and specify just the file path then it will execute that file but the process working directory will be the same as your application's working directory. Many applications, particularly games, assume that their working directory is the directory containing their EXE. In order to set that, you must create a ProcessStartInfo object, configure it appropriately and then pass it to a call to Process.Start. If you need that then read the MSDN documentation for the Process and ProcessStartInfo classes for details.
 
Thanks jmcilhinney....
I am really really new to this stuff.I looked at ProcessStartInfo Class (System.Diagnostics)
and I am still lost.Since this is my very first try at coding could you please type in the exact way it should look.
//this is what I have so far
void Button2Click(object sender, EventArgs e)
{
//below here I have no idea what to put
//to start the exe for the game listed in the previous post



Close();

}
}
}
Thanks!
I appreciate it a bunch.
Val
 
I'm typing this reply on a phone, so providing code is not really practical. I shouldn't really need to anyway though, because I'm quite sure that there are examples online already of using a ProcessStartInfo object. You create one, set the appropriate properties and than pass it as an argument to Process.Start. I've alreay mentioned the working directory so you know you have to set the property related to that and obviously you need to provide the path of the file that you want to execute. At this point, there's no reason to do more than that.
 
Yo Guys.....
Thanks for your all your information anyway jmcilhinney,but I really need an example.
Can anybody else help me out here in the request I made in the previous post?
As I said I am just learning how to code so the example I need would really help me out.
Thanks guys!
Val
 
So you really need an example but you are apparently not prepared to make any effort to search the web to find one. It doesn't take any programming experience to search the web. I've told you what to search for. You'll need to wipe your own nose.
 
Yo jmcilhinney....
I googled for help for 2 days to find some coding examples for what I want to do and I could not find anything that explains it.
So I searched for a forum where people help people that have C# questions.I found this one.No offense but like I said before I am real new at this and an example of what I am asking for would be a great help.If you personally don't want to help me any more that is your choice.I am sincere when I am telling you I appreciate what you told me previously.
Thanks anyway!
Val
 
You searched for two days before you knew that you had to use a ProcessStartInfo and set the working directory. Now that you have those keywords you can refine your search considerably. I just searched for c# processstartinfo working directory and it took me about 15 seconds to find an example. If someone gives you information then use that information. I told you what to search for and if you had serahced for it then you would already have your example and moved on. I have no issue helping you but you have already been provided with all the help you need. Now you just have to use it.
 
Back
Top Bottom