我正在尝试通过 C# 代码关闭 Microsoft Edge 上所有打开的选项卡,但无法使其正常工作。 尝试过:
Process[] edgeProcessList = Process.GetProcessesByName("MicrosoftEdgeCP");
foreach (Process theprocess in edgeProcessList)
{
if (theprocess.MainWindowHandle != IntPtr.Zero)
{
SetForegroundWindow(theprocess.MainWindowHandle);
SendKeys.SendWait("^{W}");
Thread.Sleep(3000);
}
}
以及:
foreach(Process proc in edgeProcessList.ToList())
{
proc.Kill();
}
但都不起作用。这些进程确实被杀死了,但新的进程会立即重新出现。
在调试后显示两者:
Process[] newProcessList = Process.GetProcessesByName("MicrosoftEdgeCP");
以及任务管理器中。 有没有办法做到这一点有效?
最佳答案
该进程名为“msedge”
Process[] Edge = Process.GetProcessesByName("msedge");
foreach (Process Item in Edge)
{
try
{
Item.Kill();
Item.WaitForExit(30000);
}
catch (Exception)
{
}
}
关于c# - 如何以编程方式关闭 Microsoft Edge 上的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49469807/