Every now and then my computer gets confused and thinks the printer is offline. That wouldn’t be so bad except Windows doesn’t provide a simple way to bring the printer back online. Basically you need to shutdown and restart the print spooler. I wrote this example to make that easier.
When you click the Restart button, the program executes the following code.
// Add a reference to System.ServiceProcess. using System.ServiceProcess; ... private void btnRestart_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; // Stop the spooler. ServiceController service = new ServiceController("Spooler"); if ((!service.Status.Equals(ServiceControllerStatus.Stopped)) && (!service.Status.Equals(ServiceControllerStatus.StopPending))) { lblStatus.Text = "Stopping spooler..."; lblStatus.Refresh(); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped); } // Start the spooler. lblStatus.Text = "Restarting spooler..."; lblStatus.Refresh(); service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); lblStatus.Text = "Done"; Cursor = Cursors.Default; }
The program uses the System.ServiceProcess.ServiceController class so the code makes that easier by starting with a using System.ServiceProcess directive. To use that namespace, add System.ServiceProcess to the project’s references.
When you click the button, the code creates a new ServiceController for the service named “Spooler.” If the spooler isn’t currently stopped or pending a stop, the code calls its Stop method and then waits until the spooler stops.
Now that the spooler is stopped, the code calls its Start method and waits until it is finished starting.
This is pretty easy but there is a catch. You need to run the program with sufficient privileges to stop and restart the spooler. One way to do that is to right-click on the program’s executable and select “Run as administrator.”




Hello, I was searching for this solution because the printer causes sometimes errors that are not reseted.
Using Windows 10 on a 64 bit machine.
First I get an message in the object: SC.ServiceHandle = ‘SC.ServiceHandle’ threw an exception of type ‘System.InvalidOperationException’
If I execute SC.Stop() I get:
an exception : 2147467259
message: {“Toegang geweigerd”} (translated) “Access denied”
Any suggestion.
Sorry but I don’t know what’s going wrong there. You could search the internet to see if someone else has had that problem.
Thank a lot for your code and explanation. Really appreciate.
This code line worked successfully. to get the administrator privilege you need to do this..
In Visual Studio, right click project -> Add Item -> Choose Application Manifest File ( under General for Visual C# items)
In manifest file update the following code segments
Hi Rod,
I tried running your app and get this error:
{“Cannot open Spooler service on computer ‘.’.”}
any ideas?
My only guess is that you’re not running it with administrator privileges. Look at the last paragraph of the post.
Try building the executable. Then right-click the exe file and select “Run as administrator.” that should give you permission to shutdown and restart the spooler.
Thank you so much 🙂
Very helpful – many thanks!!!