Print Spooler: Auto delete after 1 month?
-
- Forum Administrator
- Posts: 22136
- Joined: 14 Jun 2004, 02:00
- Processor: Ryzen 1700K
- Motherboard: Asus X370
- Graphics card: Asus 1060 Strix
- Memory: 16GB RAM
- Location: Where Google says
Print Spooler: Auto delete after 1 month?
Morning All,
Quick and simple question with a simple answer (hopefully).
On Windows Server 2003 is it possible to set up our printers to automatically delete spooled jobs after 30 days? If so how?
Thank you .
Quick and simple question with a simple answer (hopefully).
On Windows Server 2003 is it possible to set up our printers to automatically delete spooled jobs after 30 days? If so how?
Thank you .
JUSTICE, n A commodity which is a more or less adulterated condition the State sells to the citizen as a reward for his allegiance, taxes and personal service.
- hamin_aus
- Forum Moderator
- Posts: 18363
- Joined: 28 Aug 2003, 02:00
- Processor: Intel i7 3770K
- Motherboard: GA-Z77X-UP4 TH
- Graphics card: Galax GTX1080
- Memory: 32GB G.Skill Ripjaws
- Location: Where beer does flow and men chunder
- Contact:
Re: Print Spooler: Auto delete after 1 month?
http://support.microsoft.com/kb/946737
Method D
But instead of just running the .CMD file once-off, create a scheduled job to run it every 30 days on your print servers
Method D
But instead of just running the .CMD file once-off, create a scheduled job to run it every 30 days on your print servers
- Ron2K
- Forum Technical Administrator
- Posts: 9050
- Joined: 04 Jul 2006, 16:45
- Location: Upper Hutt, New Zealand
- Contact:
Re: Print Spooler: Auto delete after 1 month?
jamin, that's close to what he wants, but not exactly -- deleting all spooled jobs every 30 days isn't the same as deleting all spooled jobs that have been sitting there munching popcorn for 30 days. The batch file as a scheduled job is just as likely to nuke something munching popcorn for 30 seconds than something munching popcorn for 30 days.
That being said, someone with coding knowledge could hack up a Windows Service that looks at %systemroot%\system32\spool\printers\*.shd and %systemroot%\system32\spool\printers\*.spl, examines file created/modified/whatever-you-want-to-use times, and does the steps detailed in the article if the age is above a user-defined threshold.
That being said, someone with coding knowledge could hack up a Windows Service that looks at %systemroot%\system32\spool\printers\*.shd and %systemroot%\system32\spool\printers\*.spl, examines file created/modified/whatever-you-want-to-use times, and does the steps detailed in the article if the age is above a user-defined threshold.
Kia kaha, Kia māia, Kia manawanui.
-
- Registered User
- Posts: 14085
- Joined: 06 Oct 2004, 02:00
- Location: Location, Location...
- Contact:
Re: Print Spooler: Auto delete after 1 month?
This is rather interesting. If someone does write it, I'd like to look at the source code
I'll ask some folks at work about it.
I'll ask some folks at work about it.
-
- Forum Administrator
- Posts: 22136
- Joined: 14 Jun 2004, 02:00
- Processor: Ryzen 1700K
- Motherboard: Asus X370
- Graphics card: Asus 1060 Strix
- Memory: 16GB RAM
- Location: Where Google says
Re: Print Spooler: Auto delete after 1 month?
For some reason I always thought that there was a setting one could set in Windows when you ask the printer to keep jobs, I could not find it so that's why I am asking here . Will investigate jamins cmd prompt and try to make it a scheduled task .
JUSTICE, n A commodity which is a more or less adulterated condition the State sells to the citizen as a reward for his allegiance, taxes and personal service.
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Print Spooler: Auto delete after 1 month?
SykomantiS wrote:If someone does write it, I'd like to look at the source code
Code: Select all
<pseudo code>
file[] grabFiles(int days){
select files from dir where datediff[dy,timestamp]>=days
filter file[] for regex(\.(?i:)(?:shd|spl)$)
return file[]
}
void flushOldQueue(
stopQueue()
for(file f:grabFiles())
if(!f is null&&!f is directory)
f.delete()
startQueue()
)
</pseudo code>
i'd still spend time validating file headers just to be sure, but how is it the spool queue doesn't support something so simple?
<edit>
actually, the API would be the second port of call, only resorting to kludgery when successive calls to EndDocPrinter fails to clear the job...
first prize would be a managed service provided by mickeysoft themselves...
</edit>
Most people would sooner die than think; in fact, they do so - Bertrand Russel
-
- Registered User
- Posts: 14338
- Joined: 04 Sep 2004, 02:00
- Processor: i386DX Sooper
- Motherboard: A blue one
- Graphics card: A red one
- Memory: Hard drive
- Location: On a Möbius strip
- Contact:
Re: Print Spooler: Auto delete after 1 month?
Compile this C# code and let me know if it works. You can plug this app into your task scheduler I guess?
Code: Select all
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace S66SpoolClear
{
class Program
{
static ServiceController service = new ServiceController("Spooler");
static DirectoryInfo SpoolDir = new DirectoryInfo(@"C:\Windows\system32\spool\printers\");
static void Main(string[] args)
{
StopSpool();
ClearSpool();
RestartSpool();
Console.WriteLine("Done!");
Console.ReadKey();
}
static void ClearSpool()
{
Console.WriteLine("Deleting files");
foreach (FileInfo SpoolFile in SpoolDir.GetFiles())
{
if (SpoolFile.Extension == "shd" || SpoolFile.Extension == "spl")
{
if ((DateTime.Now - SpoolFile.LastWriteTime).Days >= 30)
SpoolFile.Delete();
}
}
}
static void StopSpool()
{
Console.WriteLine("Stopping spool");
service.Stop();
}
static void RestartSpool()
{
Console.WriteLine("Restarting spool");
service.Start();
}
}
}
If I weren't insane: I couldn't be so brilliant! - The Joker
- hamin_aus
- Forum Moderator
- Posts: 18363
- Joined: 28 Aug 2003, 02:00
- Processor: Intel i7 3770K
- Motherboard: GA-Z77X-UP4 TH
- Graphics card: Galax GTX1080
- Memory: 32GB G.Skill Ripjaws
- Location: Where beer does flow and men chunder
- Contact:
Re: Print Spooler: Auto delete after 1 month?
Yeah because he has Visual Studio laying aroundBladerunner wrote:Compile this C# code
Why don't you compile it with any required DLL's zip it and upload it somewhere, Annie is not a developer and AFAIK his company doesn't employ any.
A lot of people are being very classy with their code, but no-one seems to be actually spoon-feeding little orphan Annie. So here goes
Code: Select all
net stop spooler
forfiles.exe /p %systemroot%\system32\spool\printers\ /s /m *.shd /d -30 /c "cmd /c del @file"
forfiles.exe /p %systemroot%\system32\spool\printers\ /s /m *.spl /d -30 /c "cmd /c del @file"
net start spooler
- make sure you run the batch as a user with permissions to stop and start the print spooler
- make sure you have forfiles.exe, win2k3 and later should have it, but if not get it here.
-
- Registered User
- Posts: 14338
- Joined: 04 Sep 2004, 02:00
- Processor: i386DX Sooper
- Motherboard: A blue one
- Graphics card: A red one
- Memory: Hard drive
- Location: On a Möbius strip
- Contact:
Re: Print Spooler: Auto delete after 1 month?
I wouldn't just run any exe on my company's server. I'd rather read through the code myself and then compile it.
If I weren't insane: I couldn't be so brilliant! - The Joker
-
- Forum Administrator
- Posts: 22136
- Joined: 14 Jun 2004, 02:00
- Processor: Ryzen 1700K
- Motherboard: Asus X370
- Graphics card: Asus 1060 Strix
- Memory: 16GB RAM
- Location: Where Google says
Re: Print Spooler: Auto delete after 1 month?
@jamin Thanks for the script. Will play around with it today .
@Bladerunner Dont worry about it. I may not be familiar with VB but my boss is so I will let him review the code and make the decision .
@rusty They are making some improvements . In server 2008 you can now arrange your spool jobs by time & date which makes life a heck of a lot easier its just 2003 that you want to burn...
@Bladerunner Dont worry about it. I may not be familiar with VB but my boss is so I will let him review the code and make the decision .
@rusty They are making some improvements . In server 2008 you can now arrange your spool jobs by time & date which makes life a heck of a lot easier its just 2003 that you want to burn...
JUSTICE, n A commodity which is a more or less adulterated condition the State sells to the citizen as a reward for his allegiance, taxes and personal service.
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Print Spooler: Auto delete after 1 month?
using the scripted appraoch also requries that you fiddle with sc query in order to verify if the service actually restarted, (unless you enjoy being flooded with tickets )....
<obligatory> CUPS knocks the M$ spool service into a cocked hat while blind drunk and being savaged by a rodent.. </obligatory>
<obligatory> CUPS knocks the M$ spool service into a cocked hat while blind drunk and being savaged by a rodent.. </obligatory>
Most people would sooner die than think; in fact, they do so - Bertrand Russel
-
- Forum Administrator
- Posts: 22136
- Joined: 14 Jun 2004, 02:00
- Processor: Ryzen 1700K
- Motherboard: Asus X370
- Graphics card: Asus 1060 Strix
- Memory: 16GB RAM
- Location: Where Google says
Re: Print Spooler: Auto delete after 1 month?
My personal preference is the bat file. I can run that manually when needed.
JUSTICE, n A commodity which is a more or less adulterated condition the State sells to the citizen as a reward for his allegiance, taxes and personal service.