start -process -passThru无法抓住流程ID吗?

发布于 2025-01-30 11:53:41 字数 644 浏览 7 评论 0原文

我有一个PowerShell脚本,可以通过start -Process $ type -passthru通过返回的PID打开和关闭.txt .exe .exe 。但是,如果我尝试使用.png s做同样的事情,我会得到此错误:

start-process:由于系统无法找到所需的所有信息,因此无法完全运行此命令。

我正在尝试获得返回的PID,以便我可以关闭默认的照片编辑器,而无需按名称明确调用。代码样本:

$object = Get-ChildItem | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-730)} | Select-Object -Property Name  
[System.Collections.ArrayList] $filearray = $object 
$removed = $filearray[-1].Name
$open_photo = Start-Process -FilePath $removed -passthru 
$open_photo.Id

I have a PowerShell script able to open and close .txt and .exe via a returned PID from Start-process $type -Passthru. However, if I try to do this same thing with .pngs I get this error:

Start-Process : This command cannot be run completely because the system cannot find all the information required.

I am trying to get a returned PID so I can close the default photo editor without having to explicitly call it by name. Code sample:

$object = Get-ChildItem | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-730)} | Select-Object -Property Name  
[System.Collections.ArrayList] $filearray = $object 
$removed = $filearray[-1].Name
$open_photo = Start-Process -FilePath $removed -passthru 
$open_photo.Id

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文