cul*_*ter 6 .net powershell ms-word
在我们公司,我们使用Windows应用程序生成word(2010)文档.有时候文档没有正确关闭,所以另一个应用程序(是的,他们仍然称之为开发:)杀掉运行超过1分钟的单词进程.
这些被杀死的进程存储在MS Word的"文档恢复"中.在Word 2010中无法关闭这些文档恢复(选项/"保存自动回复信息..."无法解决问题).当这些"文档恢复"中充满了文档(数十或数百)时,应用程序停止生成文档,我们需要手动清除前端.
所以,我能够编写这个脚本来识别并杀死运行超过10秒的进程,但有没有办法如何正确关闭它(不杀死它)?
我发现本教程使用powershell创建和退出word文档,但如何将特定的word进程与这些MS Office方法连接以关闭文档?
$timer = 10
$date = Get-Date
if (Get-Process winword*) {
Get-Process winword | foreach {
if ((($date - $_.StartTime).Seconds) -gt $timer) {
$procID = $_.id
Write-Host -ForegroundColor Magenta "Process $procID is running longer than $timer seconds."
Write-Host -ForegroundColor Green "Killing process $procID.."
Stop-Process $procID
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
您可以尝试将焦点设置在这些窗口之一中,然后按 Alt F4 键来关闭这些进程
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
有几种方法可以获取进程窗口的句柄。
祝你好运
| 归档时间: |
|
| 查看次数: |
7490 次 |
| 最近记录: |