Execute from another program using C#
I am looking for a way to execute a program programmanically. Is there a code for when a user presses a button, the button will execute a program. Also, while the program is executing, how can I tell the application that I am working on to disable the button to prevent a user from executing again? Once the user exits the program, then the application will re-enable the button for the execution of programs again. I am working with the 3DGameStudio Main Menu, which contain 4 programs (3 are GameStudio programs and one is a manual). So, the Main Menu provides 4 buttons which show pictures. When the use presses the first picture (name of the variable: WED), it will open up a World Editor, and disables the button in the main menu so that a user can't press the button. Another example is if the user presses the second picture (variable name: MED), then it will open up a Model Editor. Note that this thread doesn't go in the Game Programming forum. I posted it here because this is the place for those who need help with C#. I hope you get the idea of what I'm talking about. :p
A process in System.Diagnostics?
Hey! Thanks for your help! The use of process works for me.
A code to execute a program.
If a user wants to execute a program by pressing a corresponding button, for example, if a user presses a calculator and the program launches a calculator, here's the code example:
Code:
public int FileNotFound = 2;
/// <summary>
/// This is a button to execute a Calculator program.
/// </summary>
public void Calculator_Click(object sender, EventArgs e)
{
try
{
// Create a new process for starting an application.
Process exec_calc = new Process();
// Go to the Windows directly and find Calc.exe
exec_calc.StartInfo.FileName = "C:\\Windows\\Calc.exe";
// Once done, start the Calculator.
exec_calc.Start()
}
catch (Win32Exception error)
{
if(error.NativeErrorCode == FileNotFound)
{
MessageBox.Show(
"You don't have a Calculator in the Accessory section.\n" +
"Go to Add/Remove Programs under Control Panel\n" +
"to install Calculator.\n" +
"\nError code: " + FileNotFound,
"Error: File Not Found.");
)
}
}
}
Hope it works for you! :)