Access denied when attempting to remove printer(尝试删除打印机时访问被拒绝)
问题描述
def on_printer_button_clicked(self, button):
for i in range(len(self.printer_buttons)):
if button == self.printer_buttons[i]:
pHandle = win32print.OpenPrinter(self.printers[i]['pPrinterName'])
win32print.DeletePrinter(pHandle)
return
所以我所做的就是打开打印机句柄并调用函数删除打印机,如您所见.这是我在运行该函数时在控制台中得到的信息:
So all I'm doing is opening the printer handle and calling the function Delete Printer, as you can see. Here's what I get in the console when I run the function:
uninstall_windowGUI.py", line 57, in on_printer_button_clicked
win32print.DeletePrinter(pHandle)
pywintypes.error: (5, 'DeletePrinter', 'Access is denied.')
我已经尝试运行 IDE(Pycharm 在管理员模式下,但仍然遇到同样的问题.关于如何继续前进的任何想法?我有点卡住了,直到我弄清楚这一点.(另外:我使用 Gtk 和 Gdk 来创建接口,如果有区别的话.)
I've tried running the IDE (Pycharm in Administrator mode, and still get the same issue. Any idea on how to move on? I'm kind of stuck until I can figure this out. (Also: I'm using Gtk and Gdk to create the interface, if that makes a differece.)
推荐答案
文档声明必须为 PRINTER_ACCESS_ADMINISTER 打开打印机句柄.这样的事情可能会奏效:
The documentation states that Printer handle must be opened for PRINTER_ACCESS_ADMINISTER. Something like this might work:
PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ACCESS_ADMINISTER}
win32print.OpenPrinter(self.printers[i]['pPrinterName'], PRINTER_DEFAULTS)
这篇关于尝试删除打印机时访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!