在 C# 中从 Msi 中的自定义操作强制重新启动

发布于 2024-07-28 03:44:46 字数 842 浏览 2 评论 0原文

我们如何在 C# 自定义操作中提示安装后重新启动计算机?

我们使用 VS 2005 的安装项目进行安装,并且需要以编程方式决定提示重新启动(因此不会在每次安装时发生,只是在某些安装上发生)。

更新:我们首先正在寻找已经内置于 MSI 自定义操作系统中的东西。 如果不存在,我们可以自行重新启动电脑,但希望避免这种情况。

更新:我们看到在 Orca 中编辑 Msi 时可以在哪里设置 REBOOT=Force,您可以在运行时通过 C# 自定义操作修改这些表吗? 我们可以将其设置为每次都重新启动,但这可能会使我们的设置变得烦人(只需要在极少数情况下重新启动)。

更新:我们尝试设置:

savedState["REBOOT"] = "Force";

从我们的自定义操作的 Install() 方法中,但没有运气。 IDictionary、savedState 似乎并没有真正做任何事情。

也尝试过:

Context.Parameters["REBOOT"] = "Force";

但我认为这个集合只是传递给自定义操作的命令行参数。

更新:有没有办法用 Orca 编辑我们的 MSI 来使这个技巧发挥作用? 也许在某些文件存在的情况下安排重新启动? 我们尚未找到如何从 C# 自定义操作设置 MSI 属性。

更新:我们尝试挂钩 AppDomain.ProcessExit 和 AppDomain.DomainUnload 并启动一个新线程并调用 Process.GetCurrentProcess().WaitForExit() ,但这些事件都不会从 C# 自定义操作中触发...

How can we prompt for a computer restart after install from within a C# custom action?

We are using VS 2005's setup project for our setup, and we need to programmatically decide to prompt for a restart (so it will not happen on every install, just on some).

UPDATE: We're looking for something that is already built into the MSI custom action system first. If that doesn't exist, we can resort to restarting the PC ourselves somehow, but would like to avoid that.

UPDATE: We see where you can set REBOOT=Force when edited the Msi in Orca, can you modify these tables from a C# custom action at runtime? We could set this to restart every time, but that might make our setup annoying (it will only need to restart on rare occasions).

UPDATE: We tried setting:

savedState["REBOOT"] = "Force";

From within the Install() method of our custom action, but no luck. It doesn't seem like the IDictionary, savedState really does anything.

Also tried:

Context.Parameters["REBOOT"] = "Force";

But I think this collection is just the command line arguments passed to the custom action.

UPDATE: Is there a way to edit our MSI with Orca to make this trick work? Maybe schedule a reboot on a condition of some file existing? We have not found how to set MSI properties from a C# custom action.

UPDATE: We tried hooking into AppDomain.ProcessExit and AppDomain.DomainUnload and starting a new thread and calling Process.GetCurrentProcess().WaitForExit() and none of those events will fire from within a C# custom action...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘香 2024-08-04 03:56:47

LanceSc 已经给了你答案。 您需要运行 ScheduleReboot,最好的方法是将其插入到以您在自定义操作中设置的自定义属性为条件的 InstallExecuteSequence 中。

正如您提到的,Wix 是实现未来灵活性的途径。 Wix 现在还包括 DTF(部署工具基础),它是一组丰富的 .NET 类库,包装了整个 Windows API。 您可以使用它从 C# 轻松访问 MSI 数据库或编写 C# 自定义操作。 如果需要,我可以提供更多相关信息。

小傻瓜 2024-08-04 03:53:44

当我在使用 user32.dll 中的 Win32 API 函数之前必须执行此操作时,我认为就是这样: ExitWindowsEx()

When I've had to do this before we used a Win32 API function from user32.dll, I think this was it: ExitWindowsEx()

独闯女儿国 2024-08-04 03:51:23

您需要添加或调用 MSI 自定义操作 ScheduleReboot http: //msdn.microsoft.com/en-us/library/aa371527(VS.85).aspx 在 InstallExecuteSequence 中,. 您可以使用 MSI 函数 MsiDoAction,http: //msdn.microsoft.com/en-us/library/aa370090(VS.85).aspx 位于自定义操作内。 请注意,安排此操作的自定义操作必须是立即自定义操作,而不是延迟的自定义操作。 这意味着您可能需要在 InstallFinalize 之后安排它。 您还可以将其添加到 InstallExecuteSequence 中,并在自定义操作设置的公共属性上设置一个条件。

You need to add or call the MSI custom action ScheduleReboot http://msdn.microsoft.com/en-us/library/aa371527(VS.85).aspx in your InstallExecuteSequence, . You can do this by using the MSI function MsiDoAction, http://msdn.microsoft.com/en-us/library/aa370090(VS.85).aspx inside a custom action. Please note that the custom action that schedules this must be an immediate custom action, not a deferred custom action. This means you will probably need to schedule it after InstallFinalize. You could also add it to the InstallExecuteSequence with a condition on a public property that your custom action sets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文