在代码中添加管理员权限请求功能

- 在gui.py中添加Windows管理员权限检测和请求代码
- 使用ctypes.windll.shell32.ShellExecuteW实现UAC权限提升
- 移除PyInstaller的uac_admin配置避免启动问题
- 优化spec文件确保interface文件正确复制
- 程序现在会在启动时自动请求管理员权限
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
yaofanguk
2026-04-10 22:45:51 +08:00
parent 0073ec80cb
commit a5a19ef2d2
2 changed files with 13 additions and 2 deletions

7
gui.py
View File

@@ -11,9 +11,16 @@ import os
import configparser
import cv2
import multiprocessing
import ctypes
from PySide6.QtCore import Qt, QTranslator
from PySide6 import QtCore, QtWidgets, QtGui
from PySide6.QtWidgets import QApplication, QFrame, QStackedWidget, QHBoxLayout, QLabel
# 请求管理员权限Windows
if sys.platform == 'win32' and not ctypes.windll.shell32.IsUserAnAdmin():
params = ' '.join([f'"{arg}"' for arg in sys.argv])
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, params, None, 1)
sys.exit(0)
from qfluentwidgets import (FluentWindow, PushButton, Slider, ProgressBar, PlainTextEdit,
setTheme, Theme, FluentIcon, CardWidget, SettingCardGroup,
ComboBoxSettingCard, SwitchSettingCard, setThemeColor, OptionsConfigItem,