KENTO⚽️XR Engineer😎
Posted on October 29, 2022
Intro
I faced the situation that I would like to launch another exe placed at a relative path of the running exe.
So I write the way down on this article so I won't forget.
Sample Code
using System;
using System.Diagnostics;
using System.IO;
using UnityEngine;
public static class Launcher
{
/// <summary>
/// relative pass
/// </summary>
private static string path = "..\\..\\..\\target.exe";
/// <summary>
/// launch target exe and kill self
/// </summary>
public static void LaunchAndKillSelf()
{
//move current directory
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
//start process
Process process = new Process();
process.StartInfo.FileName = path;
process.Start();
//kill self
Application.Quit();
}
}
Working directory is changed if the running exe was launched by another exe.
The code below is a workaround for that.
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
💖 💪 🙅 🚩
KENTO⚽️XR Engineer😎
Posted on October 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
unity3d 【Unity】How to launch another exe placed at a relative path of the running exe.
October 29, 2022