取消启动时的管理员权限

This commit is contained in:
chenxudong 2025-06-09 14:02:43 +08:00
parent a2aba153c0
commit dc0234af14
4 changed files with 15 additions and 19 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ install.spec
start.spec start.spec
build/ build/
~$据库本地运行.docx ~$据库本地运行.docx
数据库组件本地安装/
数据库组件本地安装.zip

BIN
dist/start.exe vendored

Binary file not shown.

View File

@ -1,7 +1,6 @@
import os import os
import time import time
import elevate
from loguru import logger from loguru import logger
import subprocess import subprocess
import sys import sys
@ -93,17 +92,12 @@ def start():
def kill_process_by_port(run_port): def kill_process_by_port(run_port):
# 执行netstat命令获取端口占用信息 # 执行netstat命令获取端口占用信息
cmd_netstat = ['netstat', '-ano', '-p', 'tcp'] cmd_netstat = ['netstat', '-ano', '|', 'findstr', fr':{run_port}']
result = subprocess.run(cmd_netstat, capture_output=True, text=True, shell=True) result = subprocess.run(cmd_netstat, capture_output=True, text=True, shell=True)
out = result.stdout
# 在输出中查找指定端口 if out:
pid = None arr = re.split(r'\s+', out)
pattern = fr':{run_port}\s+.*LISTENING\s+(\d+)' pid = arr[5]
match = re.search(pattern, result.stdout)
if match:
pid = match.group(1)
# 如果找到PID则终止进程
if pid: if pid:
try: try:
subprocess.run(['taskkill', '/F', '/PID', pid], check=True) subprocess.run(['taskkill', '/F', '/PID', pid], check=True)
@ -113,6 +107,7 @@ def kill_process_by_port(run_port):
else: else:
logger.info(f"端口 {run_port} 未被占用") logger.info(f"端口 {run_port} 未被占用")
def open_web(): def open_web():
webview.settings['ALLOW_DOWNLOADS'] = True webview.settings['ALLOW_DOWNLOADS'] = True
webview.settings['OPEN_DEVTOOLS_IN_DEBUG'] = False webview.settings['OPEN_DEVTOOLS_IN_DEBUG'] = False
@ -120,7 +115,6 @@ def open_web():
webview.start(debug=True) webview.start(debug=True)
if __name__ == '__main__': if __name__ == '__main__':
elevate.elevate()
kill_process_by_port(port) kill_process_by_port(port)
delete_old_files(app_log_dir, days=2) delete_old_files(app_log_dir, days=2)
start() start()