//using System.Diagnostics;
//using System.Runtime.InteropServices;
//using SHDocVw;
class Program
{
//1. 引用c:\windows\system32\shdocvw.dll
//2. 声明SetForegroundWindow
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main(string[] args)
{
ShellWindows wins = new ShellWindows();
string folder = @"D:\test";
bool found = false;
foreach (InternetExplorer w in wins)
if (w.LocationURL.Contains(
folder.Replace('\\', '/')))
{
SetForegroundWindow((IntPtr)w.HWND);
found = true;
break;
}
if (!found)
Process.Start("explorer", folder);
Console.ReadLine();
}
}
网页链接 net3.5下使用,要使用win32api来达到目的
///
/// 置前窗口
///
///
///
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetForegroundWindow(IntPtr hwnd);
Win32api.SetForegroundWindow(item.HWND);