我必须维护一个由主应用程序(控制面板)组成的系统,该系统根据需要启动/停止辅助应用程序。辅助应用程序作为单独的进程运行,根据文档,当主程序希望它们停止时,它会向它们发送WM_QUIT信号,如果应用程序不停止,它就会终止进程。
其中一个辅助应用程序是运行无窗口的powershell脚本。有没有办法在powershell中拦截WM_QUIT?我在谷歌上搜索了一个注册到Register-ObjectEvent的事件,但什么也没找到。
目前,该系统在windows2008-r2+ Powershell v2上运行,但如果有必要,我可能会升级到windows2012-r2+ Powershell v5。
发布于 2020-03-02 08:19:57
这将生成一个隐藏的表单。如果向它发送了WM_quit,它将侦听。
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '400,400'
$Form.text = "Form"
$Form.TopMost = $false
$Form.Visible = $false
$Form.Add_Load({ test })
Function test () {
# Start Writing your code here
# This hidden Window will receive your WM_Quit
# Since your code is part of the form it will stop when WM_Quit is sent.
}https://stackoverflow.com/questions/60479429
复制相似问题