Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

aardio编程,查询主板是否支持Nvme协议

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    aardio编程,查询主板是否支持Nvme协议

  2. Claude Assistant

    在 Aardio 中查询主板是否支持 NVMe 协议,可以通过以下几种方法来实现。这里提供一个更完整的解决方案,包括多种检测方法:

    import com;
    import console;
    import win.reg;
    
    // 检查主板是否支持 NVMe 的综合函数
    function checkNvmeSupport() {
        var results = {
            supported = false;
            hasNvmeDrive = false;
            hasNvmeController = false;
            hasPcieSlot = false;
            details = {};
        };
        
        // 方法1: 检查已安装的 NVMe 驱动器
        console.log("正在检查已安装的 NVMe 驱动器...");
        results.hasNvmeDrive = checkInstalledNvmeDrives(results.details);
        
        // 方法2: 检查 NVMe 控制器
        console.log("正在检查 NVMe 控制器...");
        results.hasNvmeController = checkNvmeControllers(results.details);
        
        // 方法3: 检查 PCIe 插槽信息
        console.log("正在检查 PCIe 插槽信息...");
        results.hasPcieSlot = checkPcieSlots(results.details);
        
        // 方法4: 检查 BIOS/UEFI 信息
        console.log("正在检查 BIOS/UEFI 信息...");
        checkBiosInfo(results.details);
        
        // 综合判断
        results.supported = results.hasNvmeDrive || results.hasNvmeController || results.hasPcieSlot;
        
        return results;
    }
    
    // 检查已安装的 NVMe 驱动器
    function checkInstalledNvmeDrives(details) {
        var found = false;
        details.nvmeDrives = {};
        
        try {
            // 使用 MSFT_PhysicalDisk (Windows 8/Server 2012 及以上)
            var wmi = com.Connect("winmgmts:\\\\.\\root\\microsoft\\windows\\storage");
            if (wmi) {
                var disks = wmi.ExecQuery("SELECT * FROM MSFT_PhysicalDisk");
                for disk in disks {
                    if (disk.BusType == 17) { // 17 = NVMe
                        found = true;
                        table.push(details.nvmeDrives, {
                            friendlyName = tostring(disk.FriendlyName);
                            model = tostring(disk.Model);
                            size = disk.Size ? math.floor(disk.Size / 1073741824) + " GB" : "未知";
                            mediaType = disk.MediaType == 4 ? "SSD" : "其他";
                        });
                    }
                }
            }
        } catch(e) {
            // 如果 MSFT_PhysicalDisk 不可用,尝试 Win32_DiskDrive
            try {
                var wmi2 = com.Connect("winmgmts:\\\\.\\root\\cimv2");
                if (wmi2) {
                    var drives = wmi2.ExecQuery("SELECT * FROM Win32_DiskDrive");
                    for drive in drives {
                        var interfaceType = string.lower(tostring(drive.InterfaceType) : "");
                        var pnpId = string.lower(tostring(drive.PNPDeviceID) : "");
                        
                        if (interfaceType == "nvme" || string.find(pnpId, "nvme")) {
                            found = true;
                            table.push(details.nvmeDrives, {
                                model = tostring(drive.Model);
                                size = drive.Size ? math.floor(drive.Size / 1073741824) + " GB" : "未知";
                                caption = tostring(drive.Caption);
                            });
                        }
                    }
                }
            } catch(e2) {
                console.log("检查磁盘驱动器时出错:", e2.message);
            }
        }
        
        return found;
    }
    
    // 检查 NVMe 控制器
    function checkNvmeControllers(details) {
        var found = false;
        details.nvmeControllers = {};
        
        try {
            var wmi = com.Connect("winmgmts:\\\\.\\root\\cimv2");
            if (wmi) {
                // 查询 PNP 设备
                var query = "SELECT * FROM Win32_PnPEntity WHERE " +
                           "(Name LIKE '%NVM Express%' OR " +
                           "Description LIKE '%NVM Express%' OR " +
                           "Service = 'stornvme')";
                
                var devices = wmi.ExecQuery(query);
                for device in devices {
                    if (device.Status == "OK") {
                        found = true;
                        table.push(details.nvmeControllers, {
                            name = tostring(device.Name);
                            deviceId = tostring(device.DeviceID);
                            status = tostring(device.Status);
                        });
                    }
                }
                
                // 额外检查存储控制器
                var controllers = wmi.ExecQuery("SELECT * FROM Win32_SCSIController");
                for controller in controllers {
                    var name = string.lower(tostring(controller.Name) : "");
                    if (string.find(name, "nvme") || string.find(name, "nvm express")) {
                        found = true;
                        table.push(details.nvmeControllers, {
                            name = tostring(controller.Name);
                            manufacturer = tostring(controller.Manufacturer);
                            status = tostring(controller.Status);
                        });
                    }
                }
            }
        } catch(e) {
            console.log("检查控制器时出错:", e.message);
        }
        
        return found;
    }
    
    // 检查 PCIe 插槽
    function checkPcieSlots(details) {
        var found = false;
        details.pcieSlots = {};
        
        try {
            var wmi = com.Connect("winmgmts:\\\\.\\root\\cimv2");
            if (wmi) {
                // 检查系统插槽
                var slots = wmi.ExecQuery("SELECT * FROM Win32_SystemSlot");
                for slot in slots {
                    var slotDesignation = string.lower(tostring(slot.SlotDesignation) : "");
                    var connectorType = slot.ConnectorType;
                    
                    // PCIe 相关的连接器类型
                    // 参考: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-systemslot
                    var pcieTypes = {[142]=true, [143]=true, [144]=true, [145]=true, [146]=true, [147]=true, [148]=true};
                    
                    if (pcieTypes[connectorType] || string.find(slotDesignation, "pcie") || string.find(slotDesignation, "m.2")) {
                        found = true;
                        table.push(details.pcieSlots, {
                            designation = tostring(slot.SlotDesignation);
                            status = tostring(slot.Status);
                            currentUsage = slot.CurrentUsage == 4 ? "使用中" : "空闲";
                        });
                    }
                }
            }
        } catch(e) {
            console.log("检查 PCIe 插槽时出错:", e.message);
        }
        
        return found;
    }
    
    // 检查 BIOS/UEFI 信息
    function checkBiosInfo(details) {
        details.biosInfo = {};
        
        try {
            var wmi = com.Connect("winmgmts:\\\\.\\root\\cimv2");
            if (wmi) {
                var bios = wmi.ExecQuery("SELECT * FROM Win32_BIOS");
                for item in bios {
                    details.biosInfo.manufacturer = tostring(item.Manufacturer);
                    details.biosInfo.version = tostring(item.SMBIOSBIOSVersion);
                    details.biosInfo.releaseDate = tostring(item.ReleaseDate);
                    
                    // 检查 BIOS 特性
                    if (item.BiosCharacteristics) {
                        for characteristic in item.BiosCharacteristics {
                            // 12 = BIOS 支持 PCI
                            // 7 = PCI 支持
                            if (characteristic == 12 || characteristic == 7) {
                                details.biosInfo.supportsPci = true;
                            }
                        }
                    }
                }
                
                // 获取主板信息
                var baseboards = wmi.ExecQuery("SELECT * FROM Win32_BaseBoard");
                for board in baseboards {
                    details.biosInfo.boardManufacturer = tostring(board.Manufacturer);
                    details.biosInfo.boardProduct = tostring(board.Product);
                    details.biosInfo.boardVersion = tostring(board.Version);
                }
            }
        } catch(e) {
            console.log("检查 BIOS 信息时出错:", e.message);
        }
    }
    
    // 生成报告
    function generateReport(results) {
        console.log("\n========== NVMe 支持检测报告 ==========\n");
        
        if (results.supported) {
            console.log("✓ 主板支持 NVMe 协议\n");
            
            if (results.hasNvmeDrive) {
                console.log("已安装的 NVMe 驱动器:");
                for (i, drive in results.details.nvmeDrives) {
                    console.log("  - " + (drive.friendlyName || drive.model || drive.caption));
                    console.log("    容量: " + drive.size);
                }
                console.log("");
            }
            
            if (results.hasNvmeController) {
                console.log("检测到的 NVMe 控制器:");
                for (i, controller in results.details.nvmeControllers) {
                    console.log("  - " + controller.name);
                }
                console.log("");
            }
            
            if (results.hasPcieSlot) {
                console.log("可用的 PCIe/M.2 插槽:");
                for (i, slot in results.details.pcieSlots) {
                    console.log("  - " + slot.designation + " (" + slot.currentUsage + ")");
                }
                console.log("");
            }
        } else {
            console.log("✗ 未检测到 NVMe 支持\n");
            console.log("可能的原因:");
            console.log("  1. 主板不支持 NVMe");
            console.log("  2. BIOS 中未启用 NVMe 支持");
            console.log("  3. 缺少必要的驱动程序");
            console.log("  4. 权限不足,无法访问硬件信息\n");
        }
        
        if (results.details.biosInfo.boardManufacturer) {
            console.log("主板信息:");
            console.log("  制造商: " + results.details.biosInfo.boardManufacturer);
            console.log("  型号: " + results.details.biosInfo.boardProduct);
            console.log("  BIOS 版本: " + results.details.biosInfo.version);
            console.log("");
        }
        
        console.log("========================================");
    }
    
    // 主程序
    console.log("开始检测主板 NVMe 支持...\n");
    
    var results = checkNvmeSupport();
    generateReport(results);
    
    console.log("\n提示: 要获得最准确的信息,请查阅主板制造商的官方规格说明。");
    console.pause();
    

    这个增强版的代码提供了以下功能:

    1. 多种检测方法:

      • 检查已安装的 NVMe 驱动器
      • 检查 NVMe 控制器
      • 检查 PCIe/M.2 插槽
      • 获取 BIOS 和主板信息
    2. 详细的信息收集:

      • NVMe 驱动器的型号、容量等
      • 控制器的名称和状态
      • PCIe 插槽的使用情况
      • 主板制造商和型号
    3. 友好的报告输出:

      • 清晰的检测结果
      • 详细的硬件信息列表
      • 可能的问题提示
    4. 错误处理:

      • 每个检测方法都有独立的错误处理
      • 即使某个方法失败,其他方法仍会继续执行

    使用时需要注意:

    • 需要管理员权限运行以获取完整信息
    • Windows Management Instrumentation 服务必须正在运行
    • 某些信息可能因系统版本或硬件配置而不可用

    这个解决方案提供了一个全面的 NVMe 支持检测工具,可以帮助用户了解其系统的 NVMe 兼容性。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.