Khi @AndresRohrAtlasInformatik chỉ ra, giải pháp được chấp nhận không hoạt động với Windows Vista trở lên.
Vì vậy, giải pháp của tôi là để 'đơn giản' bắt đầu thám hiểm như cửa sổ ẩn, đi đến ổ đĩa mạng và thám hiểm gần. Cái thứ hai khó hơn một chút (xem here) vì trình thám hiểm có hành vi rất đặc biệt cho nhiều cửa sổ.
ProcessStartInfo info = new ProcessStartInfo("explorer.exe", myDriveLetter);
info.WindowStyle = ProcessWindowStyle.Hidden;
Process process = new Process();
process.StartInfo = info;
process.Start();
Thread.Sleep(1000);
//bool res = process.CloseMainWindow(); // doesn't work for explorer !!
//process.Close();
//process.WaitForExit(5000);
// https://stackoverflow.com/a/47574704/2925238
ShellWindows _shellWindows = new SHDocVw.ShellWindows();
string processType;
foreach (InternetExplorer ie in _shellWindows)
{
//this parses the name of the process
processType = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
//this could also be used for IE windows with processType of "iexplore"
if (processType.Equals("explorer") && ie.LocationURL.Contains(myDriveLetter))
{
ie.Quit();
}
}
Lưu ý rằng mã này không hoạt động nữa bắt đầu từ Windows Vista. – AndresRohrAtlasInformatik