我使用 QT-Designer 用 PyQt5 创建了一个窗口。一切正常,但当我运行卡住的 exe 文件时,打开了两个进程,按下 X 后只有一个进程关闭。
有人可以帮助我吗?谢谢。
如果您需要有关该计划的更多信息,请发表评论!
编辑: 我找到了问题的地方:
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
# Run as admin
import win32com.shell.shell as shell
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
try:
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
except:
easygui.msgbox("You have to be admin.", "Error")
sys.exit()
sys.exit(app.exec_())
“#Run as admin”部分正在打开第二个进程。但为什么?也许你现在可以帮助我;)
编辑: 我从脚本中删除了这部分。我现在正在尝试修改 py2exe 脚本,以便强制用户成为管理员。这不起作用:
setup(
options = {'py2exe': {'includes': "sip, PyQt5.QtNetwork, PyQt5.QtWebKit, PyQt5.QtPrintSupport", 'compressed': True}},
windows = [{'script': file,
"icon_resources": [(1, "[Icon]")],
'uac_info': "requireAdministrator"}],
data_files = [('platforms', [
'C:/Python34/Lib/site-packages/PyQt5/plugins/platforms/qwindows.dll'
])],
)
有人知道如何强制用户成为管理员吗?
最佳答案
好的。看起来 Python 3 的 py2exe 无法强制用户成为管理员。我已向 py2exe 程序添加了一些代码以使其正常工作:
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe, sys, os
import easygui
manifest = '''
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<asmv3:trustInfo xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:security>
<asmv3:requestedPrivileges>
<asmv3:requestedExecutionLevel
level="requireAdministrator"
uiAccess="false" />
</asmv3:requestedPrivileges>
</asmv3:security>
</asmv3:trustInfo>
</assembly>
'''
file = easygui.fileopenbox("Script")
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'includes': "sip, PyQt5.QtNetwork, PyQt5.QtWebKit, PyQt5.QtPrintSupport", 'compressed': True}},
windows = [{'script': file,
"icon_resources": [(1, "[Icon]")],
'other_resources':[(24, 1, manifest)]}],
data_files = [('platforms', [
'C:/Python34/Lib/site-packages/PyQt5/plugins/platforms/qwindows.dll'
])],
)
关于python - win32com打开2个进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27999387/