如果 Windows 更新强制重新启动,如何重新启动我的应用程序?

发布于 2024-07-26 21:23:27 字数 308 浏览 4 评论 0原文

在办公室,当我晚上离开时,我很少注销或重新启动。 我只需锁定我的工作站然后回家,将所有开发工具原封不动地保留下来。

如果 Windows 更新在半夜滚动并重新启动我的计算机,我只是有点恼火,因为当我第二天早上重新登录时,我运行的任何 MS Office 应用程序或 Visual Studio 实例都会自动重新启动,打开我可能正在处理的任何文件/项目/解决方案。

我的问题是:如何让我的 Windows 窗体应用程序 (C#) 执行此操作? 如果系统自动重新启动,我的应用程序是否可以通过某种方式“注册”它想要重新启动?

At the office, when I leave for the night I very rarely log off or reboot. I simply lock my workstation and go home, leaving all my development tools exactly how I left them.

If Windows-Update rolls through and reboots my machine in the middle of the night I'm only slightly peeved because when I log back in the next morning, any MS Office application, or Visual Studio instance I had running will have already automatically restarted, opening whatever file(s)/projects/solutions I may have been working on.

My question is: How can I make my Windows Forms applications (C#) do this? Is there some way for my application to "register" that it wants to be restarted if the system automatically reboots?

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

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

发布评论

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

评论(4

执手闯天涯 2024-08-02 21:23:27

我认为RegisterApplicationRestart Win32 API 函数可能正是您所追求的,它是重新启动管理器 API 的一部分。

I think the RegisterApplicationRestart Win32 API function might be what you're after, it's part of the Restart Manager API.

萌酱 2024-08-02 21:23:27

如果您使用的是 Windows Vista 或 Windows 7,则可以使用托管重新启动和恢复 API。 该页面上的链接还指向一些有用的博客条目

http://channel9.msdn.com/posts/DanielMoth/Windows-Vista-Restart-amp-Recovery-APIs-from-management-code/

If you have Windows Vista or Windows 7, you can use the Managed Restart and Recovery API. The links on that page also point to some useful blog entries

http://channel9.msdn.com/posts/DanielMoth/Windows-Vista-Restart-amp-Recovery-APIs-from-managed-code/

凉城已无爱 2024-08-02 21:23:27

一种简单的方法是向以下注册表项添加一个条目:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

只需创建一个包含应用程序路径的值(可选地包括命令行参数)。 该应用程序将在下次启动时运行,然后该值将被删除。

A simple way is to add an entry to the following registry key :

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

Just create a value containing the path of your app (optionally including command line arguments). The app will be run at the next startup, then the value will be deleted.

你曾走过我的故事 2024-08-02 21:23:27

第 1 步:找出一种方法来区分 Windows 触发的重新启动和标准重新启动。 一种解决方案是尝试预处理消息。 对于 Windows 触发的重新启动,它们可能有所不同...或者至少在某些情况下在 Vista 中是不同的:/

步骤 2:如果您检测到这是 Windows 触发的重新启动,请添加一项计划的一次性任务。

Step 1: Figure out a way to differentiate a windows-triggered restart from a standard one. One solution would be to try preprocessing messages. They're probably different for a windows-triggered restart...or at least they are in Vista in some cases :/

Step 2: If you detect it's a windows-triggered restart, add a scheduled, one-time task.

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