Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] Process.Start() crashing external app?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Resolved [RESOLVED] [2.0] Process.Start() crashing external app?

    An application I am launching with process.start is crashing but when I run it from explorer it runs fine.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Process.Start() crashing external app?

    Do you really think that we should be able to help with so little information? What is the application? What is the code you're using to start it? What is the nature of the crash? We really shouldn't have to prompt you to provide this sort of information.
    Last edited by jmcilhinney; Sep 21st, 2007 at 08:16 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2.0] Process.Start() crashing external app?

    Quote Originally Posted by jmcilhinney
    Do you really think that we should be able to help with so little information? What is the application? What is the code you're using to start it? What is the nature of the crash? We really shouldn't have to prompt you to provide this sort of information.
    C++ Code:
    1. //COPath = C:\Program Files\Conquer 2.0\Conquer.exe
    2.             Process p = new Process();
    3.             p.StartInfo.FileName = COPath;
    4.             p.Start();

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Process.Start() crashing external app?

    Is Conquer.exe a game? Many games need to be started form their own program folder because they try to access files assuming that that is the current folder. If it's not then they crash because they fail to find the required files. In that case you'd need this:
    C# Code:
    1. Process p = new Process();
    2.  
    3. p.StartInfo.FileName = COPath;
    4. p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(COPath);
    5. p.Start();
    Note that this applies to any program that assumes that the working folder is the folder containing the executable, but that is most common in games.

    On a slightly related note, this is why you should never just use a file name alone with no folder path when accessing files in your own code. There's no guarantee that the folder you expect is going to be the working folder, so you should always qualify a file name with a folder path. If you want the folder containing your executable then you should specify that by using Application.StartupPath.
    Last edited by jmcilhinney; Sep 21st, 2007 at 09:31 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2.0] Process.Start() crashing external app?

    Quote Originally Posted by jmcilhinney
    Is Conquer.exe a game? Many games need to be started form their own program folder because they try to access files assuming that that is the current folder. If it's not then they crash because they fail to find the required files. In that case you'd need this:
    C# Code:
    1. Process p = new Process();
    2.  
    3. p.StartInfo.FileName = COPath;
    4. p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(COPath);
    5. p.Start();
    Note that this applies to any program that assumes that the working folder is the folder containing the executable, but that is most common in games.

    On a slightly related note, this is why you should never just use a file name alone with no folder path when accessing files in your own code. There's no guarantee that the folder you expect is going to be the working folder, so you should always qualify a file name with a folder path. If you want the folder containing your executable then you should specify that by using Application.StartupPath.
    Ok, thankyou.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width