- Home /
opening an external .exe file from a game
hi. im trying to make a launcher for all of my games because i have alot of them. i have tried to use this code:
#pragma strict
function OnMouseDown ()
{
System.Diagnostics.Process.Start(Application.dataPath + "Desktop");
//or directly to open external programs:
System.Diagnostics.Process.Start("RacingPlanet2Launch.exe");
}
but it doesnt work. please could somebody help me fix it? the error i get with it is:
Win32Exception: The system cannot find the file specified.
System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) System.Diagnostics.Process.Start (System.String fileName) Open Racing Planet 2.OnMouseDown () (at Assets/Open Racing Planet 2.js:5) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
Answer by Kriogenic · Feb 06, 2015 at 06:04 AM
The issue is exactly as it says, it can not find the application you wish to open.
if RacingPlanet2Launch.exe is in the same directory as the launcher the bottom line should work.
the error is coming from the line above where you open nothing, it seems you are trying to browse to your desktop which is incorrect. Remove that line completely.
function OnMouseDown ()
{
//will open if exe is in same directory as launchers exe file.
System.Diagnostics.Process.Start("RacingPlanet2Launch.exe");
//Logs the dataPath so you can see where your applications should be
Debug.Log(Application.dataPath);
//will open from the applications dataPath directory
System.Diagnostics.Process.Start(Application.dataPath + "/RacingPlanet2Launch.exe");
}
when i put the exe file in the assets folder and it gets a weird error
Not only exe file, you have to move complete package (i.e all supporting files) and it would be great if you create one sub directory.
probably because you are moving the application .exe from where the game is installed when you should be making a shortcut to that exe file and then loading that with your script.
another note is that you dont add it to unity at all. it is purely called by its directory and should not be imported into your assets folder within unity.
Right unless you want to load it from inside the actual Unity project.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182616im_/https://answers.unity.com/themes/thub/images/avi.jpg)