const path = require('path'); const fs = require('fs'); const { execSync } = require('child_process'); async function findAndSetUiRobotPath() { const userProfile = process.env.USERPROFILE; const appDataPath = path.join(userProfile, 'AppData', 'Local', 'Programs'); const uiRobotExeName = 'UiRobot.exe'; let found = false; try { // UiRobot.exeを再帰的に検索 function searchFile(dir) { try { const files = fs.readdirSync(dir); for (const file of files) { const fullPath = path.join(dir, file); const stat = fs.statSync(fullPath); if (stat.isFile() && file === uiRobotExeName) { console.log(`Found: ${fullPath}`); execSync(`setx UiRobot "${fullPath}"`, { stdio: 'inherit' }); found = true; return true; } else if (stat.isDirectory()) { if (searchFile(fullPath)) { return true; } } } } catch (err) { // アクセス拒否などのエラーは無視 } return false; } searchFile(appDataPath); if (found) { console.log('Environment variable "UiRobot" has been set.'); } else { console.log('UiRobot.exe not found in AppData\Local\Programs.'); } } catch (err) { console.error('Error:', err.message); } } findAndSetUiRobotPath();