Otiel
Otiel

Reputation: 18743

Launch program with arguments usually in shortcut target

I would like to start a process by providing it arguments (not really sure these can be called "arguments"... see below). Now this is a little special:

I tried the following:

  1. Process.Start("C:\\Path To Game\\game.exe + connect [serverip]");

    but this obviously end with an Win32Exception "The system cannot find the file specified".

  2. var psi = new ProcessStartInfo();
    psi.FileName = "C:\\Path To Game\\game.exe";
    psi.Arguments = "+ connect [serverip]";
    Process.Start(psi);
    

    and this produce an error in the GUI (the game doesn't start and says "WIN_IMPROPER_QUIT_BODY").

Any ideas how to provide these arguments to my process?

Upvotes: 0

Views: 2314

Answers (3)

Alex Filipovici
Alex Filipovici

Reputation: 32571

You have to use:

psi.Arguments = "+connect [serverip]";

(no space between + and connect).

Upvotes: 0

sa_ddam213
sa_ddam213

Reputation: 43616

Is it possible you need to set the WorkingDirectory for the game

string exePath = "C:\\Path To Game\\game.exe";
var psi = new ProcessStartInfo();
psi.FileName = exePath;
psi.Arguments = "+ connect [serverip]";
psi.WorkingDirectory = Path.GetDirectoryName(exePath);
Process.Start(psi);

Upvotes: 2

MattW
MattW

Reputation: 4628

Option 2 is the way to go there but what happened to your '+'? It's not a special character, that was just getting passed through to the command, so you need to include it at the start of psi.Arguments too.

Upvotes: 0

Related Questions