win32com开启2个进程
win32com opens 2 processes
我使用 QT-Designer 使用 PyQt5 创建了一个 window。一切正常,但是当我 运行 冻结的 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_())
“#运行 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'
])],
)
我使用 QT-Designer 使用 PyQt5 创建了一个 window。一切正常,但是当我 运行 冻结的 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_())
“#运行 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'
])],
)