以编程方式关闭 Windows 并等待常驻进程终止



Background

  • 我正在编写一个程序以在指定时间关闭Windows。我正在使用shutdown.exe来实现此功能。
  • 在我的计算机中,有一个常驻进程来记录系统活动,并在关闭 Windows 时将记录发送到服务器。当您从开始菜单关闭 Windows 时 (RuntimeBroker.exe),Windows 等待常驻进程完成发送记录(根据HKCUControl PanelDesktopHungAppTimeout)。

问题

当我用shutdown.exe关闭Windows时,它不是指HKCUControl PanelDesktopHungAppTimeout,并在完成发送记录之前强制杀死常驻进程。

问题

有没有办法(如PowerShell cmdlet或Windows中包含的命令)以编程方式关闭Windows并在关闭之前优雅地等待常驻进程的终止?

根据@An-dir的建议,我测试了一些关闭Windows的方法:

等待 HungAppTimeoutstyle="文本对齐:左;">1style="文本对齐:左;">2style="文本对齐:左;">3style="文本对齐:左;">4style="文本对齐:左;">5style="文本对齐:左;">6
# 如何关机 执行什么
RuntimeBroker.exe
运行shutdown.exeshutdown.exe
运行SlideToShutDown.exeSlideToShutDown.exe
运行Stop-ComputercmdletWmiPrvSE.exe
从锁定屏幕关闭winlogon.exe
Explorer.exe

最新更新