powershell - 带有 -Force 的 cmdlet Stop-Process 不起作用
问题描述
我在 PowerShell 窗口中输入以下命令:
(Start-Process powershell {.\scripts\skiptest\lockfile.bat} -Passthru).ID > .\pid.txt
假设 pid.txt 中保存的 PID 为 1234。其内容lockfile.bat
为:
@ECHO OFF
powershell.exe -command "$lock=[System.IO.File]::Open('Parse.java','Open','ReadWrite','None');Write-Host -NoNewLine 'Press any key to release the file...';$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')"
现在,当我尝试使用以下命令杀死较新的 PowerShell 时:
Stop-Process -Force -Id 1234
它不关闭。我怎样才能关闭它?
解决方案
$ParentPid = '1234'
$ChildProcs = Get-WmiObject -Class Win32_Process -Filter "ParentProcessID=$ParentPid" -Property ProcessId
Stop-Process -Force -id $ChildProcs.ProcessId
推荐阅读
- kotlin - 从预定义的类生成公开的 DAO 类
- android - Android 可以接受写入 NFC 标签(模拟空的 NFC 标签)吗?
- image - 用于保存和检索图像的 Flutter 工作流程
- python - Pjsip python脚本因PJ_EINVALIDOP而失败
- python-requests - 如何用python进行非线性拟合
- elasticsearch - 导出 CVS 文件时尝试达到 Kibana Max
- android - Jetpack Security 与两个主密钥的使用
- git - Git 和 Overleaf 之间的同步
- javascript - 如何在ckeditor5中添加文本
- javascript - 不使用 ID 将文本复制到剪贴板