Fixed opendeskurl() so that the created task can work on battery power
Bryan Roe committed
Feb 3, 2021 at 11:21 UTC
b1e11e04103f5f966d47831c2db3559db5c3f7cd
1 file changed
+23
-6
agents/meshcore.js
+23
-6
@@ -2624,13 +2624,30 @@ function openUserDesktopUrl(url) {
2624
switch (process.platform) {
2625
case 'win32':
2626
var user = require('user-sessions').getUsername(require('user-sessions').consoleUid());
2627
- child = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd']);
2628
- child.stderr.on('data', function () { });
2629
- child.stdout.on('data', function () { });
2630
- child.stdin.write('SCHTASKS /CREATE /F /TN MeshChatTask /SC ONCE /ST 00:00 /RU "' + user + '" /TR "' + process.env['windir'] + '\\system32\\cmd.exe /C START ' + url.split('&').join('^&') + '"\r\n');
2627
+ var taskoptions = { env: { _target: process.env['windir'] + '\\system32\\cmd.exe', _args: '/C START ' + url.split('&').join('^&'), _user: '"' + user + '"' } };
2628
+ for (var c1e in process.env)
2629
+ {
2630
+ taskoptions.env[c1e] = process.env[c1e];
2631
+ }
2632
+ var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], taskoptions);
2633
+ child.stderr.on('data', function (c) { });
2634
+ child.stdout.on('data', function (c) { });
2635
+ child.stdin.write('SCHTASKS /CREATE /F /TN MeshChatTask /SC ONCE /ST 00:00 ');
2636
+ if (user) { child.stdin.write('/RU $env:_user '); }
2637
+ child.stdin.write('/TR "$env:_target $env:_args"\r\n');
2638
+ child.stdin.write('$ts = New-Object -ComObject Schedule.service\r\n');
2639
+ child.stdin.write('$ts.connect()\r\n');
2640
+ child.stdin.write('$tsfolder = $ts.getfolder("\\")\r\n');
2641
+ child.stdin.write('$task = $tsfolder.GetTask("MeshChatTask")\r\n');
2642
+ child.stdin.write('$taskdef = $task.Definition\r\n');
2643
+ child.stdin.write('$taskdef.Settings.StopIfGoingOnBatteries = $false\r\n');
2644
+ child.stdin.write('$taskdef.Settings.DisallowStartIfOnBatteries = $false\r\n');
2645
+ child.stdin.write('$taskdef.Actions.Item(1).Path = $env:_target\r\n');
2646
+ child.stdin.write('$taskdef.Actions.Item(1).Arguments = $env:_args\r\n');
2647
+ child.stdin.write('$tsfolder.RegisterTaskDefinition($task.Name, $taskdef, 4, $null, $null, $null)\r\n');
2648
+
2649
child.stdin.write('SCHTASKS /RUN /TN MeshChatTask\r\n');
2632
- child.stdin.write('SCHTASKS /DELETE /F /TN MeshChatTask\r\n');
2633
- child.stdin.write('exit\r\n');
2650
+ child.stdin.write('SCHTASKS /DELETE /F /TN MeshChatTask\r\nexit\r\n');
2651
child.waitExit();
2652
break;
2653
case 'linux':