Thread: Execute from another program using C#

  1. #1
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    Question 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.
    Last edited by Grayson_Peddie; 04-29-2003 at 07:18 PM.
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

  2. #2
    Registered Luser
    Join Date
    Apr 2003
    Posts
    17
    Take a look at http://msdn.microsoft.com/library/de...ClassTopic.asp and see if it helps..

  3. #3
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96
    Alright! I will try it out!
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

  4. #4
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    A process in System.Diagnostics?

    Hey! Thanks for your help! The use of process works for me.
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

  5. #5
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    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!
    Last edited by Grayson_Peddie; 06-04-2003 at 12:05 PM.
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a program that will call an execute but with arguments
    By what3v3r in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2006, 09:44 PM
  2. Need help on code to execute the program
    By hibmem10 in forum C++ Programming
    Replies: 6
    Last Post: 12-24-2005, 01:42 PM
  3. Can't execute my program
    By bahruddina in forum C Programming
    Replies: 4
    Last Post: 07-13-2004, 10:19 PM
  4. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM