[英]Process.Start(“IExplore.exe”); <— Is this reliable?
Process.Start("IExplore.exe"); 的Process.Start( “IEXPLORE.EXE”);
Does this always work, on every machine ? 这在每台机器上都能正常工作吗? If not, how to do it properly ?
如果没有,怎么做得好?
... EDIT: ................................. ...编辑:.................................
The problem with Process.Start(" http://www.example.com/ "); Process.Start(“ http://www.example.com/ ”)的问题; is that we have to target a local html file, with some querystring specifying which page to load in the html frameset.
是我们必须定位一个本地html文件,其中一些查询字符串指定要在html框架集中加载哪个页面。 So our URL looks like the following:
所以我们的URL如下所示:
G:\PathToHelpFolder\index.html#search?page=1.html
If you pass this path to Process.Start, an error is generated: "cannot find the file". 如果将此路径传递给Process.Start,则会生成错误:“找不到该文件”。 This is caused by the querystring at the end.
这是由最后的查询字符串引起的。 (#search?page=1.html)
(#搜寻?页= 1.HTML)
So, we have to start explorer (or default browser would be better) with the filepath as a command line argument. 因此,我们必须使用filepath作为命令行参数来启动资源管理器(或默认浏览器会更好)。 We found the method above at the MSDN documentation.
我们在MSDN文档中找到了上述方法。 (Process.Start("IExplore.exe");) Our only question is if this method is reliable enough to deploy to a commercial app.
(Process.Start(“IExplore.exe”);)我们唯一的问题是这个方法是否足够可靠,可以部署到商业应用程序。 Mono isn't a problem, only windows systems are targeted.
单声道不是问题,只有Windows系统是目标。
... EDIT : Our solution ...... ...编辑:我们的解决方案......
Our solution was to get the default browser from the registry, and start that with the filename as argument. 我们的解决方案是从注册表中获取默认浏览器,并以文件名作为参数启动它。 (as stated in: Launching default browser with html from file, then jump to specific anchor )
(如:在文件中用html启动默认浏览器,然后跳转到特定锚点 )
If your goal is to open a browser to go to a specific page, it's better to use just the page URL: 如果您的目标是打开浏览器转到特定页面,最好只使用页面URL:
Process.Start("http://www.example.com/");
That way, the user's default browser will be used. 这样,将使用用户的默认浏览器。 (I, for one, would be annoyed to be forced into using IE.)
(对于其中一个,我会因为被迫使用IE而烦恼。)
我曾经为我构建的一个愚蠢的应用程序需要默认浏览器的名称(没有打开),我在这里找到了一个很棒的教程: http : //ryanfarley.com/blog/archive/2004/05/16/649.aspx
This should work on every machine that has an executable called IExplore.exe
in a location that Process.Start
can find by using the PATH environment variable. 这应该适用于在
Process.Start
可以使用PATH环境变量找到的位置中具有名为IExplore.exe
的可执行文件的每台计算机。
Process.Start
documentation Process.Start
文档
Starting a process by specifying its file name is similar to typing the information in the Run dialog box of the Windows Start menu.
通过指定文件名来启动进程类似于在Windows“开始”菜单的“运行”对话框中键入信息。 Therefore, the file name does not need to represent an executable file.
因此,文件名不需要表示可执行文件。 It can be of any file type for which the extension has been associated with an application installed on the system.
它可以是扩展名与系统上安装的应用程序关联的任何文件类型。 For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated.doc files with a word processing tool, such as Microsoft Word.
例如,如果您将文本文件与编辑器(如记事本)关联,则文件名可以具有.txt扩展名;如果您具有带有文字处理工具的关联.doc文件(如Microsoft Word),则文件名可以具有.doc。 Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the fileName parameter.
同样,与“运行”对话框可以接受带有或不带.exe扩展名的可执行文件名的方式相同,.exe扩展名在fileName参数中是可选的。 For example, you can set the fileName parameter to either "Notepad.exe" or "Notepad".
例如,您可以将fileName参数设置为“Notepad.exe”或“Notepad”。
If someone has renamed or removed IExplore.exe
, or it's in a location that's not in the PATH environment variable then it won't work. 如果有人重命名或删除了
IExplore.exe
,或者它位于不在PATH环境变量中的位置,那么它将无效。
However, if your goal is to open a browser then I'd go with passing the URL as others have suggested. 但是,如果您的目标是打开浏览器,那么我会像其他人建议的那样传递URL。
You can just throw a url in there as well. 你也可以在那里扔一个网址。 (
Process.Start(" http://somewebsite.com ");
) that will always work and use the standard browser. (
Process.Start(" http://somewebsite.com ");
)将始终工作并使用标准浏览器。
You probably should be directly running a HTML file so that the user's association is honoured. 您可能应该直接运行HTML文件,以便尊重用户的关联。 There's nothing more annoying to me, as a user, than having some package force me to use IE when I've clearly set my preferences to use another browser.
作为一个用户,没有什么比让我明确设置我的首选项以使用其他浏览器时使用IE强制我使用IE更令人讨厌的了。
您可以创建一个简单的HTML文件来重定向您想要的实际链接,然后启动指向该更简单URL的进程。
尝试这个:
Process.Start("file:///g:/PathToHelpFolder/index.html#search?page=1.html");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.