.net 检查Microsoft Edge是否已打开

.net 检查Microsoft Edge是否已打开,.net,microsoft-edge,mainwindow,.net,Microsoft Edge,Mainwindow,我的问题如下: 我目前正在通过.NET代码打开Microsoft Edge,以便能够读取PFD文件。但我只想用PDF文件打开Edge,如果它还没有打开的话 Edge的问题是,该窗口由ApplicationFrameHost托管,该应用程序还从应用商店托管其他Windows应用程序,如MinesWaper。因此,当我在使用Edge打开pdf文件后打开例如MineSwaper时,当前的ApplicationFrameHost MainWindowTitle是“MineSwaper” 但是,如果我启动

我的问题如下:

我目前正在通过.NET代码打开Microsoft Edge,以便能够读取PFD文件。但我只想用PDF文件打开Edge,如果它还没有打开的话

Edge的问题是,该窗口由ApplicationFrameHost托管,该应用程序还从应用商店托管其他Windows应用程序,如MinesWaper。因此,当我在使用Edge打开pdf文件后打开例如MineSwaper时,当前的ApplicationFrameHost MainWindowTitle是“MineSwaper”

但是,如果我启动代码,它应该在开始时检查Edge是否已经打开,但我无法通过ApplicationFrameHost MainWindowTitle检查它,因为它来自当前活动的ApplicationFrameHost,即“MinesWaper”,因为它是最后一个活动的ApplicationFrameHost窗口

我也无法检查MicrosoftEdge进程是否正在运行,因为它始终在运行,即使我关闭了MicrosoftEdge

您对我的问题有什么解决方案吗?

启动Edge时(至少)会创建两个进程:MicrosoftEdge和MicrosoftEdge CP

您可以尝试使用以下代码检查边缘浏览器是否已打开:

//We need to find the most recent MicrosoftEdgeCP process that is active
Process[] EdgeCPProcessList = Process.GetProcessesByName("MicrosoftEdgeCP");

Process newestEdgeCPProcess = null;

foreach (Process theprocess in EdgeCPProcessList)
{
    if (newestEdgeCPProcess == null || theprocess.StartTime > newestEdgeCPProcess.StartTime)
    {
        newestEdgeCPProcess = theprocess;
        Console.WriteLine("EdgeCP Process: "+theprocess.ProcessName.ToString());
    }
}


Process[] edgeProcessList = Process.GetProcessesByName("MicrosoftEdge");
Process newestEdgeProcess = null;

foreach (Process edgeProcess in edgeProcessList)
{
    if (newestEdgeProcess == null || edgeProcess.StartTime > newestEdgeProcess.StartTime)
    {
        newestEdgeProcess = edgeProcess;
        Console.WriteLine("Edge Process: " + edgeProcess.ProcessName.ToString());
    }
}

Console.ReadKey();
如果我们能得到ProcessName,意味着边缘已经打开。以上代码在我这方面运行良好。

启动Edge时(至少)会创建两个进程:MicrosoftEdge和MicrosoftEdge CP

您可以尝试使用以下代码检查边缘浏览器是否已打开:

//We need to find the most recent MicrosoftEdgeCP process that is active
Process[] EdgeCPProcessList = Process.GetProcessesByName("MicrosoftEdgeCP");

Process newestEdgeCPProcess = null;

foreach (Process theprocess in EdgeCPProcessList)
{
    if (newestEdgeCPProcess == null || theprocess.StartTime > newestEdgeCPProcess.StartTime)
    {
        newestEdgeCPProcess = theprocess;
        Console.WriteLine("EdgeCP Process: "+theprocess.ProcessName.ToString());
    }
}


Process[] edgeProcessList = Process.GetProcessesByName("MicrosoftEdge");
Process newestEdgeProcess = null;

foreach (Process edgeProcess in edgeProcessList)
{
    if (newestEdgeProcess == null || edgeProcess.StartTime > newestEdgeProcess.StartTime)
    {
        newestEdgeProcess = edgeProcess;
        Console.WriteLine("Edge Process: " + edgeProcess.ProcessName.ToString());
    }
}

Console.ReadKey();

如果我们能得到ProcessName,意味着边缘已经打开。上述代码在我这方面运行良好。

检查此代码的问题是,即使关闭Microsoft Edge,这两个进程仍将继续运行。我用一台刚开机的电脑检查了一下。没有这样的程序。但当我启动Edge并再次关闭它时,进程仍在后台。因此,这将在Edge当天第一次打开时起作用,但如果它已经打开,则不会起作用。您的Windows操作系统环境是什么?我使用Windows 10 Enterprise OS,在我的电脑上,如果我关闭Edge,这些进程将被关闭。因此,您的边缘浏览器似乎没有完全关闭。这是,你可以参考一下。另外,您也可以尝试。我将在周末查看它,并告诉您我的结果。检查此项的问题是,即使关闭Microsoft Edge,这两个进程仍将继续运行。我用一台刚开机的电脑检查了一下。没有这样的程序。但当我启动Edge并再次关闭它时,进程仍在后台。因此,这将在Edge当天第一次打开时起作用,但如果它已经打开,则不会起作用。您的Windows操作系统环境是什么?我使用Windows 10 Enterprise OS,在我的电脑上,如果我关闭Edge,这些进程将被关闭。因此,您的边缘浏览器似乎没有完全关闭。这是,你可以参考一下。另外,你也可以试试。我会在周末看一看,然后告诉你我的结果。