Initial version

This commit is contained in:
Stefan 2023-08-17 12:15:29 +02:00
commit 65fb7451fb
2 changed files with 39 additions and 0 deletions

31
clear-printer-spooler.bat Normal file
View file

@ -0,0 +1,31 @@
@echo off
:: Define variables
set OutputDir=D:\Applications\ClearPrinterSpooler
set TaskName=ClearPrinterSpoolerTask
set ScriptPath=%OutputDir%\ClearPrinterSpooler.bat
set ScheduleTime=04:00
set TaskFolder="\ImagePlus"
echo Creating directory %OutputDir%
if not exist %OutputDir% mkdir %OutputDir%
:: Create the batch script to clear printer spooler
echo @echo off > %ScriptPath%
echo echo Stopping Print Spooler... >> %ScriptPath%
echo net stop spooler >> %ScriptPath%
echo echo Deleting spooled print jobs... >> %ScriptPath%
echo del /Q /F C:\Windows\System32\spool\PRINTERS\*.* >> %ScriptPath%
echo echo Starting Print Spooler... >> %ScriptPath%
echo net start spooler >> %ScriptPath%
echo echo Printer spooler cleared successfully. >> %ScriptPath%
:: Check if the task exists and delete it if found
schtasks /Query /TN %TaskFolder%\%TaskName% > nul 2>&1
if %errorlevel% equ 0 (
schtasks /Delete /TN %TaskFolder%\%TaskName% /F
echo Existing task '%TaskName%' deleted.
)
:: Create the scheduled task
schtasks /Create /TN %TaskFolder%\%TaskName% /TR "%ScriptPath%" /SC DAILY /ST %ScheduleTime%