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

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# Clear Printer Spooler
You can run this script anyware on the system but make sure there is a D drive. This batch will:
1. Create the directory `D:\Applications\ClearPrinterSpooler` if it doesn't exist
1. Create the `ClearPrinterSpooler.bat` file in that directory
1. Delete the task `\ImagePlus\ClearPrinterSpoolerTask` if it exists
1. Create a task that calls the `ClearPrinterSpooler.bat` at 4:00

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%