取消启动时的管理员权限
This commit is contained in:
parent
a2aba153c0
commit
dc0234af14
|
|
@ -3,3 +3,5 @@ install.spec
|
|||
start.spec
|
||||
build/
|
||||
~$据库本地运行.docx
|
||||
数据库组件本地安装/
|
||||
数据库组件本地安装.zip
|
||||
|
|
|
|||
Binary file not shown.
32
src/start.py
32
src/start.py
|
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
import time
|
||||
|
||||
import elevate
|
||||
from loguru import logger
|
||||
import subprocess
|
||||
import sys
|
||||
|
|
@ -93,25 +92,21 @@ def start():
|
|||
|
||||
def kill_process_by_port(run_port):
|
||||
# 执行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)
|
||||
out = result.stdout
|
||||
if out:
|
||||
arr = re.split(r'\s+', out)
|
||||
pid = arr[5]
|
||||
if pid:
|
||||
try:
|
||||
subprocess.run(['taskkill', '/F', '/PID', pid], check=True)
|
||||
logger.info(f"已终止占用端口 {run_port} 的进程 (PID: {pid})")
|
||||
except subprocess.CalledProcessError:
|
||||
logger.info(f"终止进程 {pid} 失败 (可能权限不足或进程不存在)")
|
||||
else:
|
||||
logger.info(f"端口 {run_port} 未被占用")
|
||||
|
||||
# 在输出中查找指定端口
|
||||
pid = None
|
||||
pattern = fr':{run_port}\s+.*LISTENING\s+(\d+)'
|
||||
match = re.search(pattern, result.stdout)
|
||||
if match:
|
||||
pid = match.group(1)
|
||||
|
||||
# 如果找到PID则终止进程
|
||||
if pid:
|
||||
try:
|
||||
subprocess.run(['taskkill', '/F', '/PID', pid], check=True)
|
||||
logger.info(f"已终止占用端口 {run_port} 的进程 (PID: {pid})")
|
||||
except subprocess.CalledProcessError:
|
||||
logger.info(f"终止进程 {pid} 失败 (可能权限不足或进程不存在)")
|
||||
else:
|
||||
logger.info(f"端口 {run_port} 未被占用")
|
||||
|
||||
def open_web():
|
||||
webview.settings['ALLOW_DOWNLOADS'] = True
|
||||
|
|
@ -120,7 +115,6 @@ def open_web():
|
|||
webview.start(debug=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
elevate.elevate()
|
||||
kill_process_by_port(port)
|
||||
delete_old_files(app_log_dir, days=2)
|
||||
start()
|
||||
|
|
|
|||
Loading…
Reference in New Issue