我有一个简单的应用程序,可以在PowerShell脚本调用应用程序时将powerpoint文件转换为PNG文件。我需要应用程序打开并转换文件然后关闭,但应用程序打开自己的多个实例。如何才能错误地停止此循环?下面的代码示例。
### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Users\AdamSham\Documents\WorkFolder\PowerShellScriptWatcher"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $True
$watcher.EnableRaisingEvents = $True
### DEFINE ACTIONS AFTER A EVENT IS DETECTED
$Action = {
$FileName = Get-ChildItem -path C:\Users\AdamSham\Documents\WorkFolder\PowerShellScriptWatcher -recurse -Include @("*.ppt","*.pptx") | sort CreationTime -desc | select -f 1 | ForEach-Object {$_.FullName}
Set-Location "C:\Users\AdamSham\Documents\Visual Studio 2010\Projects\PowerpointToPNG\PowerpointToPNG\bin\Debug"
Start-Process ".\PowerpointToPNG.exe" $FileName
Write-Host $FileName
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY
$created = Register-ObjectEvent $watcher "Created" -Action $Action
while ($True) {Sleep 1}
此处还有调用应用程序的powershell脚本。
{{1}}