简体   繁体   English

如何使用RestartManager通过Windows Installer自定义操作重新启动explorer.exe?

[英]How do I use RestartManager to restart explorer.exe with Windows Installer custom action?

I have an installer that prompts users to restart their computer after an install. 我有一个安装程序,提示用户安装后重新启动计算机。 I would rather not have the user restart their computer in this case, and have explorer.exe just restart itself using the RestartManager API provided with Windows Vista and up. 在这种情况下,我宁愿用户不重新启动计算机,而只使用Windows Vista及更高版本提供的RestartManager API重新启动explorer.exe。

I've created a separate executable that gets copied to the local computer during install and runs after that. 我创建了一个单独的可执行文件,该文件在安装过程中复制到本地计算机,然后在其后运行。 The separate executable registers explorer.exe, shuts it down, and restarts it based on this code: http://msdn.microsoft.com/en-us/library/aa373681%28v=VS.85%29.aspx . 单独的可执行文件将注册explorer.exe,将其关闭,然后根据以下代码重新启动它: http : //msdn.microsoft.com/zh-cn/library/aa373681%28v=VS.85%29.aspx When the executable is run separately from the installer, it works as designed. 当可执行文件与安装程序分开运行时,它将按设计工作。 But when it runs as a custom action as part of an MSI package created with InstalShield, it shuts down explorer.exe but does not restart it. 但是,当它作为自定义操作作为使用InstalShield创建的MSI软件包的一部分运行时,它将关闭explorer.exe,但不会重新启动它。

I always get a 160 error code for RmRestart when it runs with the installer. 当RmRestart与安装程序一起运行时,我总是收到160错误代码。 The docs say it's an error code meaning there were invalid arguments provided. 文档说这是一个错误代码,表示提供了无效的参数。 (http://msdn.microsoft.com/en-us/library/aa373665%28v=vs.85%29.aspx). (http://msdn.microsoft.com/zh-cn/library/aa373665%28v=vs.85%29.aspx)。 I'm fairly positive that my arguments are not invalid as they work when the executable runs separately from Windows Installer. 我非常肯定我的论点不是无效的,因为当可执行文件与Windows Installer分开运行时,它们就起作用了。

I'm stuck at this point and not sure what else to do to get this working. 我停留在这一点上,不知道该怎么做才能做。 The only thing I'm uncertain of is if "0" can be a proper session handle returned from RmStartSession() with error code of 0 (Success). 我唯一不确定的是“ 0”是否可以是从RmStartSession()返回的正确会话句柄,错误代码为0(成功)。 Assuming this was wrong, I set up my executable to also take in the RmSessionKey that's created by Windows Installer before InstallValidate. 假设这是错误的,我将可执行文件设置为也接受Windows Installer在InstallValidate之前创建的RmSessionKey。 And I use that to call my executable as a deferred action. 我用它来调用我的可执行文件作为延迟动作。 I get an error of 4c3 for RmShutdown in this case, which seems to be an invalid error code. 在这种情况下,我收到RmShutdown的4c3错误,这似乎是无效的错误代码。

Cliffs: Have separate .exe that uses RestartManager API to shutdown, restart explorer.exe that works when not run with Windows Installer, but when combined, it breaks. 悬崖:有一个单独的.exe使用RestartManager API来关闭,重新启动explorer.exe可以在不与Windows Installer一起运行时使用,但是结合使用时会损坏。 Seeing error code of 160 for RmRestart(). RmRestart()的错误代码为160。 Ran out of ideas to try to get this working. 想出办法来使它起作用。 I can provide code snippets if people want... 如果人们愿意,我可以提供代码段...

Thanks for any suggestions/comments. 感谢您的任何建议/意见。

I ended up reaching a solution to this... 我最终找到了解决方案...

Rather than creating a separate executable that registers explorer.exe and shuts it down, create a MSI DLL Custom Action. 与其创建一个单独的可执行文件来注册explorer.exe并关闭它,不如创建一个MSI DLL自定义操作。 All this DLL has to have is a single function that registers explorer.exe to be restarted and use the existing restart manager session provided by Windows Installer (by default). 所有这些DLL必须具有一个功能,该功能注册将要重启的explorer.exe并使用Windows Installer提供的现有重启管理器会话(默认情况下)。 Then in your installer, add the MsiFilesInUse dialog and you'll be good to go. 然后在您的安装程序中,添加MsiFilesInUse对话框,您会很方便。

Now when the installer runs, it starts the restart manager session, and calls your MSI DLL CA, and adds explorer.exe to the list. 现在,当安装程序运行时,它将启动重新启动管理器会话,并调用您的MSI DLL CA,并将explorer.exe添加到列表中。 The list gets displayed and the user is given options to close or defer closing of the applications. 将显示该列表,并为用户提供关闭或推迟关闭应用程序的选项。

Using this method allows you to avoid having to distribute a pointless executable to the user, as well as simplifies the amount of code written greatly. 使用此方法可以避免向用户分发毫无意义的可执行文件,并大大简化了编写的代码量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何挂钩windows7 explorer.exe来隐藏文件 - How to hook windows7 explorer.exe to hide file 如何通过C ++启动explorer.exe? - How can I start explorer.exe via C++? 使用 wh_shell 挂钩自定义 windows-shell(explorer.exe 替换程序)C++ - Using wh_shell hook for custom windows-shell(explorer.exe replacement program) C++ 如何在 WIX 中使用来自 MSI 安装程序的 OrignalDatabase 并将其传递给 C++ 自定义操作代码 - How do I use the OrignalDatabase from MSI Installer in WIX and pass it to the C++ custom action code 我如何导入Shell32.dll的表地址(在explorer.exe中) - how can i import the table address of Shell32.dll (in explorer.exe) 在XP上使用Windows文件资源管理器时,停止打开explorer.exe任务栏 - Stopping the explorer.exe taskbar from opening when using the windows file explorer on XP 是否有“Legal”API退出explorer.exe? - Is there a “Legal” API to exit explorer.exe? 使用 C++ 重新启动 explorer.exe - Restarting explorer.exe using C++ 在explorer.exe中注入的dll中的无限循环 - Infinite loop in a dll injected on explorer.exe 当指定文件的路径包含空格时,如何使用 QProcess 启动 explorer.exe? - How to start explorer.exe with QProcess when the path to the specified file contains spaces?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM