欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

python 判断 cmd 有没有 “agt3tool”命令 来判断是否安装ipguard AG chatgpt 有大用 有大大用

判断系统中是否有 agt3tool 命令(用于检测 IP-Guard 安装)

在 Python 中,你可以通过以下几种方式来判断系统是否存在 agt3tool 命令,从而间接判断 IP-Guard 是否安装:

方法1:使用 which 或 where 命令(跨平台)或者使用 subprocess 检查   # OK 有大用

python
import subprocess import shutil def is_ipguard_installed():    # 检查命令是否存在(Linux/macOS/Windows均可)    if shutil.which('agt3tool') is not None:        return True        # 或者使用 subprocess 检查    try:        subprocess.run(['agt3tool', '--version'],                      stdout=subprocess.DEVNULL,                      stderr=subprocess.DEVNULL,                      check=True)        return True    except (FileNotFoundError, subprocess.CalledProcessError):        return False if is_ipguard_installed():    print("IP-Guard 已安装(检测到 agt3tool 命令)") else:    print("未检测到 IP-Guard 安装")

方法2:Windows 特定检查(通过注册表)

python
import winreg def check_ipguard_via_registry():    try:        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,                           r"SOFTWARE\TrendMicro\IP-Guard")        winreg.CloseKey(key)        return True    except FileNotFoundError:        return False if check_ipguard_via_registry():    print("通过注册表检测到 IP-Guard 安装") else:    print("注册表中未找到 IP-Guard")

方法3:检查进程或服务

python
import psutil  # 需要安装 pip install psutil def is_ipguard_running():    for proc in psutil.process_iter(['name']):        if proc.info['name'].lower() in ('ipguard.exe', 'agt3tool.exe'):            return True    return False

注意事项

  1. agt3tool 是 IP-Guard 的一个命令行工具,但不同版本可能有不同的名称

  2. 某些环境下可能需要管理员权限才能正确检测

  3. IP-Guard 可能有多种安装方式和组件,单一检测方法可能有遗漏

  4. 在 Linux/Mac 和 Windows 上的检测方式可能不同

最可靠的方法是结合多种检测方式,或参考 IP-Guard 官方文档确认其安装标志。


普通分类: