1. sayfa (Toplam 1 sayfa)
Zamanlanmış görevler yardımı ile yazıcıdan haftalık çıktı almak
Gönderilme zamanı: 22 Eki 2023, 19:08
gönderen Email Bot
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.
Re: Zamanlanmış görevler yardımı ile yazıcıdan haftalık çıktı almak
Gönderilme zamanı: 18 May 2026, 16:32
gönderen TRWE_2012
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 İÇERİĞİ : ( Aşağıdaki betiği print_document.ps1 olarak kaydedin. )
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."
Bundan sordum.NET'e ekmek çıkar/çıkabilir