如何打开父文件夹中的exe?例如调试\文件夹1\文件夹2文件夹2和文件夹1中存在exe我希望它,所以当我点击按钮与exe在folder2它打开了一个exe在folder1
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); } }
1条答案
按热度按时间omvjsjqw1#