简体   繁体   中英

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:

这是我的消息框显示的游戏路径

Thanks in advance

Set work dir with game directory like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM