test.js•2.65 kB
/**
* 测试 Windows 自动化 MCP 功能
*/
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
async function test() {
console.log('🧪 测试 Windows 自动化功能...\n');
// 测试 1: PowerShell
console.log('测试 1: PowerShell 命令');
try {
const { stdout } = await execAsync('powershell -Command "Get-Date"');
console.log('✓ PowerShell 工作正常');
console.log(' 当前时间:', stdout.trim());
} catch (error) {
console.log('✗ PowerShell 测试失败:', error.message);
}
console.log('');
// 测试 2: 文件系统
console.log('测试 2: 文件系统');
try {
const { stdout } = await execAsync('dir "%USERPROFILE%\\Desktop"', { shell: 'cmd.exe' });
console.log('✓ 文件系统访问正常');
console.log(' 可以访问桌面目录');
} catch (error) {
console.log('✗ 文件系统测试失败:', error.message);
}
console.log('');
// 测试 3: 进程列表
console.log('测试 3: 进程管理');
try {
const { stdout } = await execAsync('tasklist /FO CSV /NH', { shell: 'cmd.exe' });
const lines = stdout.trim().split('\n');
console.log('✓ 进程管理正常');
console.log(` 当前运行 ${lines.length} 个进程`);
} catch (error) {
console.log('✗ 进程管理测试失败:', error.message);
}
console.log('');
// 测试 4: 剪贴板
console.log('测试 4: 剪贴板');
try {
await execAsync('powershell -Command "Set-Clipboard -Value \'Test from MCP\'"');
const { stdout } = await execAsync('powershell -Command "Get-Clipboard"');
if (stdout.trim() === 'Test from MCP') {
console.log('✓ 剪贴板操作正常');
} else {
console.log('⚠ 剪贴板内容不匹配');
}
} catch (error) {
console.log('✗ 剪贴板测试失败:', error.message);
}
console.log('');
// 测试 5: 系统信息
console.log('测试 5: 系统信息');
try {
const command = `
$os = Get-CimInstance Win32_OperatingSystem
Write-Output "$($os.Caption) $($os.Version)"
`;
const { stdout } = await execAsync(`powershell -Command "${command.replace(/"/g, '\\"')}"`, {
shell: 'powershell.exe'
});
console.log('✓ 系统信息获取正常');
console.log(' 系统:', stdout.trim());
} catch (error) {
console.log('✗ 系统信息测试失败:', error.message);
}
console.log('');
console.log('========================================');
console.log('✅ 基础功能测试完成!');
console.log('========================================');
}
test().catch(console.error);