在Windows Server中自动启动我自己的脚本



几个客户端使用扫描程序并将.tiff文件发送到共享文件夹。此扫描仪无法将这些结果传输到 pdf。如何启动脚本以自动将此.tiff文件传输到.pdf?我在 Windows Server 2012 中有哪些变体?如果此脚本在每次创建新.tiff文件后都能正常工作,那就更好了。

监视服务器目录中的文件更改

启动监控.ps1

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "D:source"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true  
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "D:log.txt" -value $logline
}    
### DECIDE WHICH EVENTS SHOULD BE WATCHED 
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5}

如何使用

Create a new text file
Copy & paste the above code
Change the following settings to your own needs:
folder to monitor: $watcher.Path = "D:source"
file filter to include only certain file types: $watcher.Filter = "*.*"
include subdirectories yes/no: $watcher.IncludeSubdirectories = $true
Save and rename it to StartMonitoring.ps1
Start monitoring by Right click » Execute with PowerShell

若要停止监视,只需关闭 PowerShell 窗口即可

要从.tiff转换为 PDF,请尝试:

$InputLocation = "C:convert"
$tool = 'C:Program Files (x86)PDFCreatorPDFCreator.exe'
$tiffs = get-childitem  -filter *.tif -path $InputLocation
foreach($tiff in $tiffs)
{
$filename = $tiff.FullName
$pdf = $tiff.FullName.split('.')[0] + '.pdf'

'Processing ' + $filename  + ' to ' + $pdf      
$param = "-sOutputFile=$pdf"
Start-Process $tool -ArgumentList ('/IF"' + $filename + '" /OF"' + $pdf + '/NoPSCheck /NoStart')
}

相关内容

最新更新