尝试移除打印机时拒绝访问 [英] Access denied when attempting to remove printer

查看:134
本文介绍了尝试移除打印机时拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

这篇关于尝试移除打印机时拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆