winforms 如何打开父文件夹中的exe?

zrfyljdw  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(176)

如何打开父文件夹中的exe?
例如
调试\文件夹1\文件夹2
文件夹2和文件夹1中存在exe
我希望它,所以当我点击按钮与exe在folder2它打开了一个exe在folder1

omvjsjqw

omvjsjqw1#

private void OpenEXE_BtnClick(object sender, RoutedEventArgs e)
{
   var currentFolder = Directory.GetCurrentDirectory();
        var parentFolder = Path.GetDirectoryName(currentFolder);
        var exeFile = Path.Combine(parentFolder, "{FileName}");
        try
        {
            using (Process myProcess = new Process())
            {
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.FileName = exeFile;
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
            }
        }
        catch (Exception ex)
        {
            //Console.WriteLine(ex.Message);
            MessageBox.Show(
                "Some thing happend when trying run background backup!!" + Environment.NewLine + ex.Message,
                "Running Background Backup", MessageBoxButton.OK, MessageBoxImage.Error);
        }
}

相关问题