Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
✨ feat(ALL): 实现单实例检测
Browse files Browse the repository at this point in the history
 - 禁止启动多个NCD,这样会导致一些奇怪的问题出现
  • Loading branch information
HeartfeltJoy committed Sep 29, 2024
1 parent 09ae2eb commit aff4951
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@

if __name__ == "__main__":

# 检查是否已经有 NCD 在运行了, 如果有则取消运行
for proc in psutil.process_iter(['name']):
if proc.info['name'] == "NapCat-Desktop.exe":
sys.exit()

# 调整程序 log 输出
Logger()

# 检查是否以管理员模式启动, 非管理员模式尝试获取管理员权限
# 获取管理员权限成功后退出原有进程
if not ctypes.windll.shell32.IsUserAnAdmin():
logger.warning("非管理员模式启动, 尝试获取管理员权限")
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
sys.exit()

# 检查是否已经有 NCD 在运行了, 如果有则取消运行
for proc in psutil.process_iter():
logger.debug(f"检测进程名称: {proc.name()}")
if proc.name() == "NapCatQQ-Desktop.exe":
logger.warning("检测到已有 NapCatQQ-Desktop 进程运行, 请先关闭后再运行")
sys.exit()

# 启动主程序
# 第三方库导入
from creart import it
Expand Down

0 comments on commit aff4951

Please sign in to comment.