Napo
Napo

Reputation: 553

c# Process Start launch the desired application but that application doesn't work well

I have a program where I can launch multiple games. I have one game that creates a json file with the player progress, the problem is that when I open this game manually (from windows) the json file is created correctly and the game works well, but when I open the same game from my application, the game is executed, but doesn't work well because the json file is never created and when I try to read another json I created previously the game can't read them. I checked if the gamepath was wrong in my program, but it isn't. I read some other posts about process.start, the only one I've seen useful is about process impersonation, but I don't know how to use it or for what do you use it. I think my problem is about lack of permissions.

This is my code where I launch my games:

string downloadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
            "Outlands Adventure Client");               
string gamePath = Path.Combine(downloadPath, currentGameInfo.GameName, currentGameInfo.GameName + ".exe");
MessageBox.Show(gamePath);
Process.Start(gamePath);

And this is gamePath that my messagebox shows:

And this is gamePath that my messagebox shows

Thanks in advance

Upvotes: 0

Views: 327

Answers (1)

Kahn
Kahn

Reputation: 193

Set work dir with game directory like:

var process = new System.Diagnostics.Process();
process.StartInfo.WorkingDirectory =  <...>;
process.StartInfo.FileName = <...>;
process.Start();

Upvotes: 3

Related Questions