Python 管理员权限打开PyQt QLabel外部连结用什么方法,pyqtqlabel,当我用管理员权限打开外部


当我用管理员权限打开外部连结(URL)时,会出现错误:

shellexecute failed (error 2)

我的程序需要管理员权限。

先谢谢任何帮助我的朋友。

测试代码:

from PyQt5.QtWidgets import * from PyQt5.QtCore import * from win32com.shell import shell import win32con, win32event, win32process from win32com.shell import shellcon import sys, ctypes class Win(QWidget):     def __init__(self):         super().__init__()         self.resize(100, 100)         version = QLabel('''<a style= "color:#55aaff; text-decoration:none; font-size:11pt; font-family:Consolas; font-weight: bold;" \         href="http://www.google.com">Open Url</a>''', self)         version.setOpenExternalLinks(True) def runAsAdmin(wait=True):     cmd = sys.executable     params = " ".join(['"{}"'.format(x) for x in sys.argv])     procInfo = shell.ShellExecuteEx(nShow = win32con.SW_SHOWNORMAL,     fMask = shellcon.SEE_MASK_NOCLOSEPROCESS,     lpVerb = 'runas',     lpFile = cmd,     lpParameters = params)     if wait:         procHandle = procInfo['hProcess']         obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE)         rc = win32process.GetExitCodeProcess(procHandle) if not ctypes.windll.shell32.IsUserAnAdmin():     runAsAdmin() else:     app = QApplication(sys.argv)     win = Win()     win.show()     sys.exit(app.exec_())

编橙之家文章,

评论关闭