Allowing non-admin users to unstick the print spooler
- by Reafidy
I currently have an issue where the print que is getting stuck on a central print server (windows server 2008). Using the "Clear all documents" function does not clear it and gets stuck too. I need non-admin users to be able to clear the print cue from there work stations.
I have tried using the following winforms program which I created and allows a user to stop the print spooler, delete printer files in the "C:\Windows\System32\spool\PRINTERS folder" and then start the print spooler but this functionality requires the program to be runs as an administrator, how can I allow my normal users to execute this program without giving them admin privileges?
Or is there another way I can allow normal user to clear the print que on the server?
Imports System.ServiceProcess
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ClearJammedPrinter()
End Sub
Public Sub ClearJammedPrinter()
Dim tspTimeOut As TimeSpan = New TimeSpan(0, 0, 5)
Dim controllerStatus As ServiceControllerStatus = ServiceController1.Status
Try
If ServiceController1.Status <> ServiceProcess.ServiceControllerStatus.Stopped Then
ServiceController1.Stop()
End If
Try
ServiceController1.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped, tspTimeOut)
Catch
Throw New Exception("The controller could not be stopped")
End Try
Dim strSpoolerFolder As String = "C:\Windows\System32\spool\PRINTERS"
Dim s As String
For Each s In System.IO.Directory.GetFiles(strSpoolerFolder)
System.IO.File.Delete(s)
Next s
Catch ex As Exception
MsgBox(ex.Message)
Finally
Try
Select Case controllerStatus
Case ServiceControllerStatus.Running
If ServiceController1.Status <> ServiceControllerStatus.Running Then ServiceController1.Start()
Case ServiceControllerStatus.Stopped
If ServiceController1.Status <> ServiceControllerStatus.Stopped Then ServiceController1.Stop()
End Select
ServiceController1.WaitForStatus(controllerStatus, tspTimeOut)
Catch
MsgBox(String.Format("{0}{1}", "The print spooler service could not be returned to its original setting and is currently: ", ServiceController1.Status))
End Try
End Try
End Sub
End Class