分類:[C#]
2018/09/03(Mon) 23:30:18 編集(投稿者)
C#で任意のエクスプローラ(フォルダ)を閉じたいです。
Windows10環境となります。
下記ロジックで、開かれているエクスプローラを全て閉じることはできますが、
タスクバーまで消えて焦りました。
最悪このロジックで、タスクバー以外の起動しているエクスプローラを消すでも、要件を満たせるので、
EXPLORERの中身がタスクバーであるという、判断方法を教示頂けると助かります。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
// DLL インポートの宣言
[DllImport("kernel32.dll")]
private extern static int TerminateProcess(IntPtr hProcess, UInt32 uExitCode);
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
foreach (Process oProcess in Process.GetProcessesByName("EXPLORER")) {
TerminateProcess(oProcess.Handle, 1);
while (!oProcess.HasExited) {
Application.DoEvents();
}
}
}
}
}
どうぞよろしくお願い致します。