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


基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01