Module meshcore: Add 'wmi' console command (#7826)

PTR committed May 25, 2026 at 17:43 UTC 3e3322b861dd46f580d84b5770cc7efa311ebc40
1 file changed +27 -1
agents/meshcore.js
+27 -1
@@ -4432,7 +4432,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4432 if (require('os').dns != null) { availcommands += ',dnsinfo'; }
4433 try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
4434 if (process.platform == 'win32') {
4435 - availcommands += ',bitlocker,cs,wpfhwacceleration,uac,volumes,rdpport,domaininfo,printers';
4435 + availcommands += ',bitlocker,cs,wpfhwacceleration,uac,volumes,rdpport,domaininfo,printers,wmi';
4436 if (bcdOK()) { availcommands += ',safemode'; }
4437 if (require('notifybar-desktop').DefaultPinned != null) { availcommands += ',privacybar'; }
4438 try { require('win-utils'); availcommands += ',taskbar'; } catch (ex) { }
@@ -4602,6 +4602,32 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4602 });
4603 break;
4604 }
4605 + case 'wmi':
4606 + if (process.platform != 'win32') {
4607 + response = 'Unknown command "wmi", type "help" for list of available commands.';
4608 + break;
4609 + }
4610 + if (args['_'].length < 2 || args['_'].length > 3) {
4611 + response = 'Execute a WMI query.\r\nUsage: wmi namespace "query" [(a)sync][(p)retty]\r\n' +
4612 + 'Example: wmi [ROOT\\]CIMV2 "SELECT Name,ProcessId FROM Win32_Process WHERE Name=\'meshagent.exe\'" ap\r\n';
4613 + break;
4614 + }
4615 + var opt = (args['_'][2]|| '').toLowerCase();
4616 + var ns = args['_'][0].trim();
4617 + if (!/^root\\\w/i.test(ns)) { ns = 'ROOT\\' + ns; }
4618 + var q = (args['_'][1]).trim();
4619 + var wmi = require('win-wmi-fixed');
4620 + var output = function (res) { sendConsoleText(res && res[0] ? JSON.stringify(res, null, ((opt.indexOf('p') !== -1) ? 2 : 0)) : 'No results', sessionid); };
4621 + var error = function (e) { var msg = (e && e.message) ? e.message : (typeof e === 'string' ? e : JSON.stringify(e)); sendConsoleText('Error: ' + msg, sessionid);};
4622 + sendConsoleText('Performing query. Response can take a while (sometimes >60s)', sessionid);
4623 + if (opt.indexOf('a') !== -1) {
4624 + wmi.queryAsync(ns, q)
4625 + .then( output )
4626 + .catch( error );
4627 + } else {
4628 + try { output(wmi.query(ns, q)); } catch (e) { error(e); }
4629 + }
4630 + break;
4631 case 'translations': {
4632 response = JSON.stringify(coretranslations, null, 2);
4633 break;