Zamanlanmış görevler yardımı ile yazıcıdan haftalık çıktı almak
- Email Bot
- Kilobyte2

- Mesajlar: 398
- Kayıt: 20 Mar 2022, 23:50
- Teşekkür etti: 2 kez
- Teşekkür edildi: 35 kez
Zamanlanmış görevler yardımı ile yazıcıdan haftalık çıktı almak
zamanlanmış görev ile yazıcıdan haftalık yada aylık yada 2 haftada bir misal tarzında nasıl görev oluşturabilirim görev word dosyasını açıyor misal ama print ettiremiyorum.
- TRWE_2012
- Zettabyte1

- Mesajlar: 15650
- Kayıt: 25 Eyl 2013, 13:38
- cinsiyet: Erkek
- Teşekkür etti: 2734 kez
- Teşekkür edildi: 5656 kez
Re: Zamanlanmış görevler yardımı ile yazıcıdan haftalık çıktı almak
***********************************************************************************************************************************Email Bot yazdı: 22 Eki 2023, 19:08 zamanlanmış görev ile yazıcıdan haftalık yada aylık yada 2 haftada bir misal tarzında nasıl görev oluşturabilirim görev word dosyasını açıyor misal ama print ettiremiyorum.

Kod: Tümünü seç
# print_document.ps1
# Silently prints a Word document via COM automation.
# Compatible with Windows PowerShell 5.1 and PowerShell 7.x
param(
[string]$DocumentPath = "C:\Users\YourUser\Documents\weekly_report.docx",
[string]$PrinterName = "" # Leave empty to use default printer
)
$ErrorActionPreference = "Stop"
$logFile = Join-Path $PSScriptRoot "print_log.txt"
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp | $Message" | Out-File -FilePath $logFile -Append -Encoding UTF8
}
try {
Write-Log "Starting print job for: $DocumentPath"
if (-not (Test-Path $DocumentPath)) {
throw "File not found: $DocumentPath"
}
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$word.DisplayAlerts = 0 # wdAlertsNone
$doc = $word.Documents.Open($DocumentPath, $false, $true) # ReadOnly = true
if ($PrinterName -ne "") {
$word.ActivePrinter = $PrinterName
Write-Log "Printer set to: $PrinterName"
}
$doc.PrintOut()
Write-Log "PrintOut() command sent successfully."
Start-Sleep -Seconds 5 # Wait for spooler to receive the job
$doc.Close($false)
$word.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($doc) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
Write-Log "Print job completed successfully."
} catch {
Write-Log "ERROR: $_"
exit 1
}
Read-Host "`nPress ENTER to exit."