Added console command to toggle Connected Standby on Windows.

Bryan Roe committed Apr 23, 2021 at 18:23 UTC 88857b7a66d8db20ad5d5de9a6bfa8a05e633d12
1 file changed +46 -1
agents/meshcore.js
+46 -1
@@ -2753,7 +2753,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
2753 case 'help': { // Displays available commands
2754 var fin = '', f = '', availcommands = 'agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg';
2755 if (require('os').dns != null) { availcommands += ',dnsinfo'; }
2756 - if (process.platform == 'win32') { availcommands += ',safemode,wpfhwacceleration,uac'; }
2756 + if (process.platform == 'win32') { availcommands += ',cs,safemode,wpfhwacceleration,uac'; }
2757 if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
2758 if (process.platform != 'freebsd') { availcommands += ',vm'; }
2759 if (require('MeshAgent').maxKvmTileSize != null) { availcommands += ',kvmmode'; }
@@ -2768,6 +2768,51 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
2768 response = "Available commands: \r\n" + fin + ".";
2769 break;
2770 }
2771 + case 'cs':
2772 + if (process.platform != 'win32')
2773 + {
2774 + response = 'Unknown command "cs", type "help" for list of avaialble commands.';
2775 + break;
2776 + }
2777 + switch (args['_'].length)
2778 + {
2779 + case 0:
2780 + try
2781 + {
2782 + var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
2783 + response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
2784 + }
2785 + catch(e)
2786 + {
2787 + response = "This machine does not support Connected Standby";
2788 + }
2789 + break;
2790 + case 1:
2791 + if ((args['_'][0].toUpperCase() != 'ENABLE' && args['_'][0].toUpperCase() != 'DISABLE'))
2792 + {
2793 + response = "Proper usage:\r\n cs [ENABLE|DISABLE]";
2794 + }
2795 + else
2796 + {
2797 + try
2798 + {
2799 + var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
2800 + require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled', args['_'][0].toUpperCase() == 'ENABLE' ? 1 : 0);
2801 +
2802 + cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
2803 + response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
2804 + }
2805 + catch (e)
2806 + {
2807 + response = "This machine does not support Connected Standby";
2808 + }
2809 + }
2810 + break;
2811 + default:
2812 + response = "Proper usage:\r\n cs [ENABLE|DISABLE]";
2813 + break;
2814 + }
2815 + break;
2816 case 'agentupdate':
2817 require('MeshAgent').SendCommand({ action: 'agentupdate', sessionid: sessionid });
2818 break;