完成卸载相关功能

This commit is contained in:
chenxudong 2025-06-16 15:20:08 +08:00
parent 5529700151
commit a91c77bf92
1 changed files with 41 additions and 0 deletions

41
src/Uninstall.py Normal file
View File

@ -0,0 +1,41 @@
import shutil
import subprocess
import time
import tkinter as tk
from tkinter import messagebox
from loguru import logger
def delete_service(service_name):
stop_command = ["sc", "stop", service_name]
delete_command = ["sc", "delete", service_name]
subprocess.run(stop_command, capture_output=True, text=True)
subprocess.run(delete_command, capture_output=True, text=True)
time.sleep(5)
pass
def start_uninstall():
logger.info("开始清理服务")
service_names = {'ComacDatabase', 'ComacMariaDB'}
for service in service_names:
delete_service(service)
logger.info("开始清理数据")
dirs = [rf'D:\database\logs', rf'D:\database\mariadb', rf'D:\database\jdk']
for dir in dirs:
shutil.rmtree(dir)
logger.info('清理完成10秒钟后自动退出')
time.sleep(10)
pass
if __name__ == '__main__':
# 创建主窗口(但不显示)
root = tk.Tk()
root.withdraw() # 隐藏主窗口
# 弹出确认对话框
response = messagebox.askyesno("确认卸载", "确定卸载?")
if response:
start_uninstall()
else:
logger.info("卸载取消")