動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
処理概要
外部ソフトを起動したい。
https://qiita.com/7of9/items/a78d42389deda90f5aaa
で使ったようなShellExecute()を利用するかと思ったが、以下を見ていているとProcess.Start()が便利そうとのこと。
Process.Start()は内部的にはShellExecute()をコールしている。
関連
Visual Studio | WPF > 終了処理 > shutdown | reboot > System.Diagnostics.Process.Start()
にてProcess.Start()は使った。
code
MainWindow.xaml
<Window x:Class="_171110_t1525_Explorer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_171110_t1525_Explorer"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Width="200" Height="30" Content="Open Folder" Click="Button_Click"/>
</Grid>
</Window>
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace _171110_t1525_Explorer
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = "Explorer.exe";
psi.Arguments = "C:\\";
psi.UseShellExecute = true;
psi.CreateNoWindow = true;
var proc = System.Diagnostics.Process.Start(psi);
}
}
}
実行
ボタンをクリックしたらExplorerが起動してCドライブを表示する。