python - Access denied when attempting to remove printer -
def on_printer_button_clicked(self, button): in range(len(self.printer_buttons)): if button == self.printer_buttons[i]: phandle = win32print.openprinter(self.printers[i]['pprintername']) win32print.deleteprinter(phandle) return
so i'm doing opening printer handle , calling function delete printer, can see. here's in console when run function:
uninstall_windowgui.py", line 57, in on_printer_button_clicked win32print.deleteprinter(phandle) pywintypes.error: (5, 'deleteprinter', 'access denied.')
i've tried running ide (pycharm in administrator mode, , still same issue. idea on how move on? i'm kind of stuck until can figure out. (also: i'm using gtk , gdk create interface, if makes differece.)
the documentation states printer handle must opened printer_access_administer. might work:
printer_defaults = {"desiredaccess":win32print.printer_access_administer} win32print.openprinter(self.printers[i]['pprintername'], printer_defaults)