Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用每个选项卡的PID获取Internet explorer选项卡的URL?_C#_Internet Explorer - Fatal编程技术网

C# 如何使用每个选项卡的PID获取Internet explorer选项卡的URL?

C# 如何使用每个选项卡的PID获取Internet explorer选项卡的URL?,c#,internet-explorer,C#,Internet Explorer,我有我的应用程序,它可以用特定的URL触发Web浏览器。 程序结束后,我想关闭已打开的网页/选项卡 通过调用带有参数a的EXE文件。进程名称b。URL中存在的字符串 详细问题 我用了C#方法 我能够找到所有选项卡的进程ID foreach (Process theprocess in processlist) { if (theprocess.ProcessName == "iexplore") { Console.WriteLine("Process: {0}\tID

我有我的应用程序,它可以用特定的URL触发Web浏览器。 程序结束后,我想关闭已打开的网页/选项卡

通过调用带有参数a的EXE文件。进程名称b。URL中存在的字符串

详细问题

我用了C#方法

我能够找到所有选项卡的进程ID

foreach (Process theprocess in processlist) {
    if (theprocess.ProcessName == "iexplore") {
        Console.WriteLine("Process: {0}\tID: {1}\tWindow name: {2}",
            theprocess.ProcessName, theprocess.Id, theprocess.MainWindowTitle
        );
    }
}
目前我只能获得进程的窗口标题…在IE8中,只能看到主进程的一个窗口标题

如果我有每个标签的PID,如何找到标签的URL…并且只杀死那个标签

我得到了他的帮助

使用SHDocVw; .

foreach(新ShellWindowsClass()中的InternetExplorer ieInst)
控制台写入线(ieInst.LocationURL)

有一种方法可以获取每个IExplorer实例的URL

向项目中添加参考“Microsoft Internet控件”

这段代码是

**foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
        {
            System.Console.WriteLine(ieInst.LocationURL);
        }**
生成exe和Interop.SHDocVw.dll


它将工作…:)

在IE7和更高版本中,下面的代码将只杀死URL中有匹配字符串的选项卡

   foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindows())
   {
        String url = ieInst.LocationURL;
        if (url.Contains("google"))
        {
            ieInst.Quit();
        }
   }
要聚焦特定选项卡,代码为:

   foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindows())
   {
        String url = ieInst.LocationURL;
        if (url.Contains("google"))
        {
            int val = ieInst.HWND;
            IntPtr hwnd = new IntPtr(val);
            ShowWindow(hwnd, SW_MAXIMISE);
            SetForegroundWindow(hwnd);
        }
   }

好消息,但你为什么要自言自语o/Coz evryon查看了它,没有人回应:)直到我自己找到了解决方案并分享了tat:使用此代码将抛出两个错误。应该使用“ShellWindows()”而不是“ShellWindowsClass()”。