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


基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01