spoolsv 'access denied' work around

F

FrankPeck

On occasion, a custom CAD/CAM program I wrote hangs the printer up. I read that the files waiting to be printed reside in "C:\Windows\System32\Spool\printers". I tried just deleting files in that folder programmatically, but found Windows locked one them. Apparently some Kernel Mode Driver deep in the bowels of Windows got indigestion! I got the idea to stop the spooler program called spoolsv.exe, but I get an "access denied" error using the code below. (For Each was looking for more than one instance, which I first thought may be the problem.) I decided to give the user access permission by right clicking on the spoolsv.exe file, but editing "Full Control" has been greyed out. Now I feel like a step child!


Has anyone found a way to stop the spoolsv.exe programmatically so that I may delete the spooler files, and get my customer up and running without Stopping spoolsv.exe in Services.msc, drilling down folder to delete files, and finally, restarting the computer?


Private Sub BtnKill_Click_1(sender As Object, e As EventArgs) Handles BtnKill.Click
Dim p As System.Diagnostics.Process
Try
For Each p In System.Diagnostics.Process.GetProcesses()
Dim sProcess As String = "spoolsv"
If p.ProcessName = sProcess Then
'p.Kill()
'p.Close()
'p.U (lol)
MsgBox("spooler service is stopped.")
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Continue reading...
 
Back
Top Bottom