以编程方式终止并重新启动 explorer.exe 的最简洁方法是什么?
大家好,
我正在开发一个 Windows 程序,其安装需要重新启动 explorer.exe。我知道“重新启动计算机以完成安装”是这里的标准方法,但我希望我的安装程序为用户提供仅重新启动资源管理器的选项,以便他们可以立即开始使用我的程序。最好的方法是什么?当然,我可以找到并终止该进程,但这看起来相当恶心。是否有一些技巧可以让资源管理器认为用户正在注销并彻底关闭?
谢谢!
Greetings all,
I'm working on a Windows program whose installation necessitates restarting explorer.exe. I know "Reboot your computer to complete the installation" is the standard method here, but I'd like my installer to give users the option of just restarting Explorer so they can start using my program immediately. What's the best way to do that? Of course I could just find and kill the process, but that seems rather icky. Is there some trick to, say, make Explorer think the user is logging off and close cleanly?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是 MSI 安装吗?
您是否考虑过使用重新启动管理器?
重新启动管理器将检测哪些进程正在保持文件/句柄打开并需要重新启动,并允许您自动停止/启动这些进程而无需重新启动。
Is this an MSI install?
Have you considered using the Restart Manager?
Restart Manager will detect which processes are holding files/handles open and need to be restarted, and allow you to automatically stop/start those processes without a restart.
我可以尝试调用 ExitProcess 或 TerminateProcess 来停止 explorer.exe。
I could try to call ExitProcess or TerminateProcess to stop explorer.exe.
我不知道你是否可以实现这个,但我从以下位置下载了 PsTools:
http:// technet.microsoft.com/en-us/sysinternals/bb896649
然后我编写了以下批处理文件,该文件杀死并执行explorer.exe进程:
您也可以尝试与PSTools的作者联系
TechNet 网站上的 Mark Russinovich。
I don't know if you can implement this, but I downloaded PsTools from:
http://technet.microsoft.com/en-us/sysinternals/bb896649
Then I wrote the following batch file which kills and then executes the explorer.exe process:
You can also try getting in touch with the author of PSTools
Mark Russinovich on the TechNet site.
您可以向其发送 WM_ENDSESSION 消息。
这可能会欺骗它认为计算机正在关闭。然后它会释放所有资源,关闭所有打开的资源管理器窗口等。
然后当它关闭时,您可以重新启动该进程。
You could send it the WM_ENDSESSION message.
That might trick it into thinking the computer is shutting down. Then it will hopefully free all resources, close all open explorer windows, etc.
Then when it is closed, you can restart the process.
我在构建后事件中使用 powershell,如下所示:
它通常会自动重新启动
I use powershell in my post build events like this:
It generally auto restarts fine