Macuyiko
Macuyiko

Reputation: 85

VB.NET Process.Start() immediately stops

I'm having a strange problem with the following code, I'm writing a game launcher in VB.NET:

Dim gameProcess As Process = New Process()
gameProcess.StartInfo.UseShellExecute = False
gameProcess.StartInfo.FileName = TextBox2.Text
gameProcess.Start()
Debug.Print("Game started")
gameProcess.WaitForExit()
Debug.Print("Game stopped")

This code is working fine with most programs, but with some of them (Age of Empires e.g.), I get the following:

Game started

Game stopped

I see the game running for a split second in the task manager, but it immediately closes! Does anyone know why? When I run the game from Windows, it works fine.

I've also tried with Shell, same problem.

And I've tried with cmd.exe and the /C argument, same problem (note that when I type cmd.exe /C path_to_game_exe in the Windows Run Dialog, the game also starts fine), it's only when I launch it from the VB.NET app that it gives problems.

My last idea was to write a temporary batch file and starting that one, but that seems like an ugly solution.

Upvotes: 0

Views: 4128

Answers (3)

ZippyV
ZippyV

Reputation: 13028

Another option you can try: set the working directory property in the startinfo. You can find this info by looking at the properties of the games' shortcut in your startmenu.

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx

Upvotes: 2

ZippyV
ZippyV

Reputation: 13028

It could be the copy protection that detects the debugger on your system and exits the process.

Try compiling the game in Release mode and run your application when Visual Studio is not running.

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 415810

A lot of games use a launcher app that starts the game in separate process and then closes.

Upvotes: 2

Related Questions