none
Launching Another Application RRS feed

  • Question

  • Basically, my question might not be as simple as you think.

    I am trying to launch another application(in this case, a small community game) with this code:

    System.Diagnostics.Process.Start(txtDrive.Text + @":\Program Files\The Odyssey Online Classic\Odyssey.exe");

    (Note: In my program, there is a text box that lets the user enter the drive in which the game is installed...C, D, etc. That then gets the drive they've entered, and adds it to the rest of the file path.)

    However, I've run into some issues. Normally with this game, when Odyssey.exe runs, it initiates the game caches and resources, such as graphics, sounds, music, etc. However, when I launch it from my program, by clicking the button containing that code above, the game gives me an error saying certain game resource files cannot be found. When I run the game with the Shortcut that comes when you download the game, it works fine, but I want to be able to launch the game from my program.

    Someone please help me out? Or tell me if it's not on my end, like if the game developer needs to change something, and it's out of my control? Or can I do something to fix this, and change my code so that it fully runs the game or what?

    Please and thank you!

    Sunday, January 8, 2012 1:16 AM

Answers

  •                 Process process = new Process();
                    process.StartInfo.FileName = txtDrive.Text + @":\Program Files\DVD Maker\DVDMaker.exe";
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.WorkingDirectory = txtDrive.Text + @":\Program Files\DVD Maker";
                    process.StartInfo.RedirectStandardOutput = true;
                    process.Start();

    This is the code that worked for me. Thank you to TLF_KoBe and, Family Tree Mike, and Rehan Bhachura for helping me come to this conclusion.
    • Marked as answer by The 4lpha Sunday, January 8, 2012 11:46 PM
    Sunday, January 8, 2012 11:46 PM

All replies

  • See if the shortcut you noramlly use to start the app has a setting for "Start In".  This is the folder the process is normally launched from in a shortcut.  If it is set, you probably need to start the process in that folder from your application.  To do so, you would use the Process.Start overload which takes a StartInfo object, and set the StartInfo.WorkingDirectory property.
     

    --
    Mike
    Sunday, January 8, 2012 2:14 AM
  • Sorry, I don't think I'm quite understanding you. (Sorry, I'm new to C#)

    Could you give me some example code possibly of what you mean?

    Sunday, January 8, 2012 2:47 AM
  • if you right click on the shortcut, that normally starts the application, and select properties, there is a text box there with text to the left of it that says "Start in".  This is what he is referring to.  The thought here is that you need to set the "Working Directory" to the correct directory for the application to find its files.  The "Working Directory" is set through the ProcessStartInfo that is associated with the Process object.  So it would be something like:

     

    myProcess.StartInfo.WorkingDirectory = txtDrive.Text + @":\Program Files\The Odyssey Online Classic";
    

     


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
    Sunday, January 8, 2012 3:10 AM
  •  

    Process process = new Process(txtDrive.Text + @":\Program Files\The Odyssey Online Classic\Odyssey.exe");
    process.StartInfo.UseShellExecute = true;
    process.Start();

    This should work for you. Make sure you have using System.Diagnostics in your using statements.

    If it doesn't then you might need to add:

    process.StartInfo.WorkingDirectory = txtDrive.Text + ":\\";

    Check this out for more documentation:

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

     


    I code at: http://techlifeforum.net


    • Edited by TLF_KoBE Sunday, January 8, 2012 3:25 AM
    • Proposed as answer by REHAN BHARUCHA Sunday, January 8, 2012 6:41 AM
    Sunday, January 8, 2012 3:14 AM
  • Here is another discussion with an example using the WorkingDirectory property in the responses.

    --
    Mike
    Sunday, January 8, 2012 3:19 AM
  •  

    Process process = new Process(txtDrive.Text + @":\Program Files\The Odyssey Online Classic\Odyssey.exe");
    process.StartInfo.UseShellExecute = true;
    process.Start();

    This should work for you. Make sure you have using System.Diagnostics in your using statements.

    If it doesn't then you might need to add:

     

    process.StartInfo.WorkingDirectory = txtDrive.Text + ":\\";
    

    Check this out for more documentation:

     

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

     


    I code at: http://techlifeforum.net


    I am getting "'System.Diagnostics.Process' does not contain a constructor that takes 1 arguments" on 

     

    new Process(txtDrive.Text + @":\Program Files\The Odyssey Online Classic\Odyssey.exe");


     


    if you right click on the shortcut, that normally starts the application, and select properties, there is a text box there with text to the left of it that says "Start in".  This is what he is referring to.  The thought here is that you need to set the "Working Directory" to the correct directory for the application to find its files.  The "Working Directory" is set through the ProcessStartInfo that is associated with the Process object.  So it would be something like:

     

    myProcess.StartInfo.WorkingDirectory = txtDrive.Text + @":\Program Files\The Odyssey Online Classic";
    

     


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
    Also, when I try to add that in, it doesn't work because I haven't declared myProcess. How could I declare this?
    • Edited by The 4lpha Sunday, January 8, 2012 4:42 AM
    Sunday, January 8, 2012 4:34 AM
  • My bad... I typed that code out w/ out testing it.

    Process process = new Process();
    process.StartInfo.FileName = txtDrive.Text + @":\Program Files\The Odyssey Online Classic\Odyssey.exe";
    



    I code at: http://techlifeforum.net
    • Proposed as answer by REHAN BHARUCHA Sunday, January 8, 2012 6:41 AM
    Sunday, January 8, 2012 5:21 AM
  • Hi,

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    
    namespace StartApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    Process process = new Process();
                    Console.WriteLine("Enter The Drive : ");
                    String str = Console.ReadLine().ToString();
                    process.StartInfo.FileName = str + @":\Program Files\DVD Maker\DVDMaker.exe";
                    process.StartInfo.UseShellExecute = true;
                    process.StartInfo.WorkingDirectory = str + @":\Program Files\DVD Maker";
                    process.StartInfo.RedirectStandardOutput = true;
                    process.Start();
                    Console.ReadLine();
                }
                catch (Exception e) {
                 Console.WriteLine(e.Message.ToString());
                 Console.Read();
                }
            }
        }
    }
    
    

    I have used a console application to start and application DVDMaker.exe, You can use the path as specified by TLF sir and you.

     

    When you useShellExecute it means that all the dependencies of the .exe application you are starting will have open access by the application if you turn it false, and application requires any dependencies, it will throw an exception as you said in your question. Setting the UseShellExecute to true, you must specify the WorkingDirectory or else the application will assume that DVDMaker.exe is in the project output directory and on not finding it will throw an exception. So use WorkingDirectory to specify where your exe file is located... in your case it would be

    txtDrive.Text + @":\Program Files\The Odyssey Online Classic";

     


    Please mark the posts as answer if they help you or unpropose as answer if they dont help you.

    Thanks

    Rehan Bharucha - The Tech Robot

    MCTS, MCITP, MCPD, MCT, MCC

    • Edited by REHAN BHARUCHA Sunday, January 8, 2012 6:41 AM
    • Proposed as answer by REHAN BHARUCHA Sunday, January 8, 2012 6:42 AM
    • Marked as answer by The 4lpha Sunday, January 8, 2012 11:43 PM
    • Unmarked as answer by The 4lpha Sunday, January 8, 2012 11:45 PM
    • Unproposed as answer by REHAN BHARUCHA Monday, January 9, 2012 5:39 AM
    • Proposed as answer by REHAN BHARUCHA Monday, January 9, 2012 5:39 AM
    Sunday, January 8, 2012 6:40 AM
  •                 Process process = new Process();
                    process.StartInfo.FileName = txtDrive.Text + @":\Program Files\DVD Maker\DVDMaker.exe";
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.WorkingDirectory = txtDrive.Text + @":\Program Files\DVD Maker";
                    process.StartInfo.RedirectStandardOutput = true;
                    process.Start();

    This is the code that worked for me. Thank you to TLF_KoBe and, Family Tree Mike, and Rehan Bhachura for helping me come to this conclusion.
    • Marked as answer by The 4lpha Sunday, January 8, 2012 11:46 PM
    Sunday, January 8, 2012 11:46 PM