[英]Process.Start(“IExplore.exe”, “http://google.com”) Not Launching On VM. Works on Server and Local
如上标题
Process.Start("IExplore.exe", "http://google.com")
无法在我正在使用的VM上启动IE。 但是,在服务器真实计算机和本地计算机上执行时,它将正确启动。
尝试了以下内容:
Process.Start("IEXPLORE.EXE", "-nomerge http://google.com/");
如Post Process.Start(“ IEXPLORE.EXE”)中建议的那样,启动后立即触发Exited事件。为什么?
和
try
{
Process.Start("http://google.com");
}
catch (System.ComponentModel.Win32Exception)
{
Process.Start("IExplore.exe", "http://google.com");
}
和
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
任何建议,不胜感激
您在VM上正确安装了IE:D? 无论如何,尝试以管理员身份运行该应用程序可能是因为VM上的UAC设置“错误”。
尝试这个...
Process.Start("http://www.google.com");
它将使用您的默认浏览器启动该网站。 假设这是Internet Explorer,那就很好了。
这是一个精简的类,如果您想进行IE自动化,可能会很有用。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using SHDocVw;
using mshtml;
public class InternetExplorerInstance
{
public InternetExplorer Instance;
public static InternetExplorerInstance GetCurrentInternetExplorerInstance()
{
InternetExplorer currentInternetExplorer = CurrentInternetExplorer();
if ( currentInternetExplorer != null )
{
return new InternetExplorerInstance( currentInternetExplorer );
}
return null;
}
private InternetExplorerInstance( InternetExplorer ie )
{
Instance = ie;
}
public static void Iterate()
{
GetInternetExplorers();
}
private static IEnumerable<InternetExplorer> GetInternetExplorers()
{
ShellWindows shellWindows = new ShellWindowsClass();
List<InternetExplorer> allExplorers = shellWindows.Cast<InternetExplorer>().ToList();
IEnumerable<InternetExplorer> internetExplorers = allExplorers.Where( ie => Path.GetFileNameWithoutExtension( ie.FullName ).ToLower() == "iexplore" );
return internetExplorers;
}
public static void LaunchNewPage( string url )
{
InternetExplorer internetExplorer = GetInternetExplorers().FirstOrDefault();
if ( internetExplorer != null )
{
internetExplorer.Navigate2( url, 0x800 );
WindowsApi.BringWindowToFront( (IntPtr) internetExplorer.HWND );
}
else
{
internetExplorer = new InternetExplorer();
internetExplorer.Visible = true;
internetExplorer.Navigate2( url );
WindowsApi.BringWindowToFront((IntPtr) internetExplorer.HWND);
}
}
}
并非所有代码都包括在内,但对于开始来说应该足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.