我想在 Windows 照片查看器中打开一个图像,然后使用 PowerShell 自动关闭它。我将如何实现这一目标?
我尝试使用Start-Process
cmdlet 使用默认应用程序打开图像并让它返回关联的进程 ID。图像已打开,但我没有得到进程 ID。这可能是因为 Windows 照片查看器进程包含在dllhost.exe
.
PS C:\Users\Public\Pictures> $process = Start-Process -FilePath .\Wiki-error.jpg -PassThru Start-Process : 该命令无法完全运行,因为系统无法找到所需的所有信息。在 line:1 char:12
+ $process = Start-Process -FilePath .\Wiki-error.jpg -PassThru + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell。 Commands.StartProcessCommand PS C:\Users\Public\Pictures> $process.ID
PS C:\Users\Public\Pictures> Stop-Process $process.ID
Stop-Process:无法将参数绑定到参数“Id”,因为它为空。在 line:1 char:14 + Stop-Process $process.ID + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Stop-Process], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell .Commands.StopProcess 命令
我运行 PowerShell 2.1 和 Windows 7。有什么建议吗?