如何启动和使用现有应用程序(资源管理器) [英] How to start and use existing application (explorer)

查看:83
本文介绍了如何启动和使用现有应用程序(资源管理器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有启动带有提供的文件夹路径的资源管理器的程序.

我在该事件中的代码:

Hi all!

I have program which launches explorer with provided folderpath.

My code in that event:

.
.
string argument = "select," + e.Uri.LocalPath;
Process.Start("explorer.exe", argument);
.
.



工作得很好,但选择另一条路径时,这将与劳克所选路径新的探险.最后,我有多个浏览器,这不只是正确的...

如果现有应用程序已经在运行,该如何使用?我正在使用C#和.Net4平台.

希望你有主意

干杯!



Works just fine, but when selecting another path this will lauch new explorer with selected path. In the end I have multiple explorers and that is not just right...

How do I use existing application if it is already running? Im using C# and .Net4 platform.

Hope you got idea

Cheers!

推荐答案

生成外部进程几乎从来不是一个好的解决方案.应该用作最后的手段.

我真的不明白为什么启动浏览器.它可能未与您的应用程序通信.如果用户需要资源管理器窗口,则他/他可以自己完成.如果大多数用户这样做,大多数用户都会感到恼火.

考虑替代方法:使用System.Windows.Forms.WebBrowser控件,请参见:
http://msdn.microsoft.com/en-us/library/system. windows.forms.webbrowser.aspx [ ^ ]
.

使用这样的组件:
文件系统TreeView [在C#2.0中使用Treeview控制器的文件资源管理器 [我的C#资源管理器 [
Spawning of an external process is almost never a good solution; should be used as as last resort.

I don''t really understand why starting the Explorer; it probably is not communicating with your application. If the user need an Explorer window, she/he can do it by herself/himself. Most users can be only irritated if you do it for them.

Consider the alternative: use System.Windows.Forms.WebBrowser control instead, see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx[^]
.

Use a component like this:
Filesystem TreeView[^],
File Explorer using Treeview controller in C# 2.0[^],
My Explorer In C#[^].

—SA


看看
Take a look at IRunningObjectTable[^]

Allows you to gain access to, and control, a running instance of IE using COM.

Regards
Espen Harlinn



您可以取消应用程序启动的前一个进程,然后启动一个新进程.为了确保终止正确的进程,您需要存储已启动进程的BaseAddress,然后将其与要关闭的进程进行比较.
Hi,
you can kill the previous process that your application started, and start a new one. In order to be sure to kill the right process, you''ll need to store the BaseAddress of started process, and then compare later to the one that you want to close.
List<int32> list = new List<int32>(); //list which will have identifiers of processes that you''ve started
...
...
//starting a new process
Process[] procs = Process.GetProcessesByName("explorer"); //get all explorers
foreach (Process p in procs)
{
    int baseAdd = p.MainModule.BaseAddress.ToInt32();
    if(list.Contains(baseAdd))
       p.Kill(); //kill previous process
}
var r = Process.Start("explorer.exe", argument);
list.Add(r.MainModule.BaseAddress.ToInt32); //store process started by you
</int32></int32>


问候


这篇关于如何启动和使用现有应用程序(资源管理器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆