打开资源管理器窗口并等待其关闭
我有一个程序正在打开某个文件夹的资源管理器窗口,但我想在资源管理器窗口关闭后立即执行操作,但如果我使用以下代码:
Process proc = Process.Start("explorer.exe", "D:\\");
proc.WaitForExit();
它正在根据需要打开资源管理器窗口,但 WaitForExit 命令具有没有效果,它就直接过去了。
是否有其他打开资源管理器窗口的方式可以让我知道用户何时关闭它?
I have a program that is opening an explorer window to a certain folder but i want to perform an action right after the explorer window is closed, but if I use the following code:
Process proc = Process.Start("explorer.exe", "D:\\");
proc.WaitForExit();
It is opening the explorer window as desired but the WaitForExit command has no effect and it just goes right past it.
Is there a different way of opening the explorer window that will be able to let me know when it is closed by the user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题在 The Old New Thing:
他提供了一些您可能会使用的解决方案(大量使用 PInvoke),例如使用 这个。
最后,您可能会更轻松地使用其他类型的文件浏览器(可能来自您可以更好控制的 C# 库),而不是资源管理器。
The problem is explained pretty well at The Old New Thing:
He offers a couple solutions you could probably use (with some heavy use of PInvoke), like using something like this.
In the end it might just be easier for you to use some other type of file browser maybe from a C# library somewhere that you have more control over, rather than explorer.
无法重新生成错误。刚刚尝试过这个:
它会阻止当前线程并等待我关闭资源管理器窗口。确保您没有在要阻止的线程之外的另一个线程上执行该命令。另请确保通过导入以下 .reg 文件将窗口的每个实例设置为启动
explorer.exe
的新实例:您需要重新启动计算机才能生效。
Cannot regenerate the error. Just tried this:
and it blocks the current thread and waits until I close the explorer windows. Make sure that you're not executing the command on another thread than the one you want to block. Also make sure that you set every instance of a window to start a new instance of
explorer.exe
via importing below .reg file:You'll need to restart your computer for this to take effect.