commit 65fb7451fb410b4c2b466760efc1ae732e7e7a43 Author: Stefan Date: Thu Aug 17 12:15:29 2023 +0200 Initial version diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b537b0 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/clear-printer-spooler.bat b/clear-printer-spooler.bat new file mode 100644 index 0000000..b2bdf58 --- /dev/null +++ b/clear-printer-spooler.bat @@ -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%