简体   繁体   English

如何通过PowerShell关闭pdf文件

[英]How to close a pdf file via PowerShell

How to close a PDF file via PowerShell? 如何通过PowerShell关闭PDF文件?

I have tried Stop-Process but it doesn't work. 我已经尝试过Stop-Process,但是它不起作用。

Why use PoSH to do this? 为什么要使用PoSH做到这一点? Are you starting a pdf in your code you need to close vs the user closing it? 您是要在代码中启动pdf还是关闭用户? What pdf viewer are you using, Adobe, FoxIt. 您使用的是什么PDF查看器,Adobe,FoxIt。 MS built-in reader...etc..? MS内置阅读器...等? Is this just one pdf or multiple? 这只是一个pdf还是多个? Why not just close the 为什么不关闭

Just look for the PDF viewer process and close it, which ever one you were using from the example list above. 只需查找PDF查看器进程并将其关闭,即可使用上面的示例列表中的任何一个。

Get-Process -Name AcroRd32

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
429      22     9816      25476       0.28   5428   1 AcroRd32
522      49    90020     116200       1.78  17100   1 AcroRd32

Stop-Process -Name AcroRd32 -Force

If you trying to call a specifc file runnning in the reader, then do this (though this will still just shut down the reader) 如果您尝试在读取器中调用特定文件,请执行此操作(尽管这仍然会关闭读取器)

(Get-WmiObject win32_process `
-Filter {name = 'AcroRd32.exe' and commandline like '%ActiveDirectoryDesignGuide%'}) |
Select CommandlIne,ProcessId | Format-List -Force

CommandlIne : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "D:\Documents\ActiveDirectoryDesignGuide.pdf"
ProcessId   : 8176

CommandlIne : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" --type=renderer /prefetch:1  
              "D:\Documents\ActiveDirectoryDesignGuide.pdf"
ProcessId   : 14484

Stop-Process -Id (Get-WmiObject win32_process `
-Filter {name = 'AcroRd32.exe' and commandline like '%ActiveDirectoryDesignGuide%'}).ProcessId -Force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM