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)
这篇关于尝试删除打印机时访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尝试删除打印机时访问被拒绝


- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01