Question

I am writing a client for my gaming community and one of the functions of this client is to launch a game via the client with parameters that will enable our community mod pack on launch.

When I press the button, the game begins to launch and as soon as the program opens (the icon pops up in the task bar), it closes instantly.

Is there something I am missing that is needed to keep the launched exe running?

Here is my code:

private void btnLaunchGame_Click(object sender, EventArgs e)
    {
        string armaPath = gameDir+"/Expansion/beta/";
        string filename = Path.Combine(armaPath, "arma2oa.exe");
        string launchParams = "-noSplash -noFilePatching -showScriptErrors \"-name=Meta\" \"-mod=I:/Steam/steamapps/common/Arma 2;expansion;expansion/beta;expansion/beta/expansion;servermods/@HC_DAYZ;servermods/@HC_WEAPONS;servermods/@HC_EXTRAS;servermods/@HC_ACE\"";
        System.Diagnostics.Process.Start(filename, launchParams);
    }//close Game Launch

Any ideas is appreciated!

I have a .bat file that will execute the game flawlessly with the launch args listed below, this could possibly help pinpoint the cause of my problem: http://puu.sh/5CGKk.png (couldn't get code to paste in a readable format).

Was it helpful?

Solution

Try using Process:

        Process process = new Process();
        process.StartInfo.FileName = "arma2oa.exe";
        process.StartInfo.Arguments = "-noSplash -noFilePatching -showScriptErrors \"-name=Meta\" \"-mod=I:/Steam/steamapps/common/Arma 2;expansion;expansion/beta;expansion/beta/expansion;servermods/@HC_DAYZ;servermods/@HC_WEAPONS;servermods/@HC_EXTRAS;servermods/@HC_ACE\"";
        process.StartInfo.WorkingDirectory = gameDir + "/Expansion/beta/";
        process.Start();

It may be what exe require working directory to be set. Or it will crash, unable to load resources.

If that doesn't works, then perhaps you need to add

            process.WaitForInputIdle();

before exiting function running process. I don't know why, but running Acrobat Reader without this wait may sometimes cause a wierd effect: Acrobat is running, but the document, passed via arguments, is not shown. Perhaps something to do with Garbage collector or Process itself.

OTHER TIPS

Try following

using (Process process = new Process())
{
   ProcessStartInfo startInfo = new ProcessStartInfo("C:\Program Files\Arma2oa\Arma2oa.exe");
   startInfo.Arguments = "-noSplash -noFilePatching -showScriptErrors \"-name=Meta\" \"-mod=I:/Steam/steamapps/common/Arma 2;expansion;expansion/beta;expansion/beta/expansion;servermods/@HC_DAYZ;servermods/@HC_WEAPONS;servermods/@HC_EXTRAS;servermods/@HC_ACE\"";
   process.StartInfo = startInfo;
   process.Start();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top