允许非pipe理员用户取消打印后台处理程序

我目前有一个问题,打印队列卡在中央打印服务器(Windows Server 2008)上。 使用“清除所有文件”function不清除它,也卡住了。 我需要非pipe理员用户才能从工作站清除打印队列。

我曾尝试使用我创build的以下Winforms程序,并允许用户停止后台打印程序,删除“C:\ Windows \ System32 \ spool \ PRINTERS文件夹”中的打印机文件,然后启动后台打印程序,但是此function需要程序以pipe理员身份运行,我如何允许普通用户执行此程序而不授予pipe理员权限?

还是有另一种方式,我可以让普通用户清除服务器上的打印队列?

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 

您可以创build一个设置为以admin身份运行的计划任务,并授予普通用户启动该计划的权限。 有点像setuid如何在Unix上工作。

然而,这不是你的问题所必需的。 您可以更改打印后台处理程序服务的权限,以便普通用户可以启动和停止它。 但是对于serverfault来说这是一个更好的问题。

用“runas”动词执行delete命令:

 var p = new Process(); p.StartInfo.Verb = "runas"; p.StartInfo.FileName = "cmd.exe"; //add your delete command, etc. as args to the process 

一般而言,您也可以通过修改其清单来使应用程序需要提升:

https://stackoverflow.com/questions/1215443/show-uac-prompt-when-launching-an-app