private Process pc;
[DllImport("user32.dll", SetLastError = true)]
static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
private void ProcessAction()
{
if ((pc == null || pc.HasExited))
{
System.Diagnostics.Process.Start(
"iexplore.exe",
"http://www.baidu.com"
);
}
else
{
//进程获得焦点
IntPtr handle = pc.MainWindowHandle;
SwitchToThisWindow(handle, true);
}
}
判断是否浏览器是否打开某个网页
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.ToLower().Equals("iexplore"))
{
if (ie.LocationURL.ToLower().IndexOf("www.baidu.com") >= 0)
{
}
}
}
C# Process线程
最新推荐文章于 2024-04-18 11:35:37 发布