1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-27 05:33:31 +00:00

Updated, so if dispatch specified without user, checks to see if current user is TSID 0, and sets SYSTEM if so.

This commit is contained in:
Bryan Roe
2020-01-08 09:52:28 -08:00
parent 36d1362deb
commit 85b487631a
2 changed files with 11 additions and 3 deletions

View File

@@ -63,7 +63,6 @@ function dispatch(options)
this.parent.emit('connection', s);
});
var child = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd']);
child.stderr.on('data', function (c) { });
child.stdout.on('data', function (c) { });
@@ -74,7 +73,16 @@ function dispatch(options)
}
else
{
child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /TR "' + process.execPath + ' -b64exec ' + str + '"\r\n');
if (require('user-sessions').getProcessOwnerName(process.pid).tsid == 0)
{
// LocalSystem
child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /RU SYSTEM /TR "' + process.execPath + ' -b64exec ' + str + '"\r\n');
}
else
{
// Running as logged in user
child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /TR "' + process.execPath + ' -b64exec ' + str + '"\r\n');
}
}
child.stdin.write('SCHTASKS /RUN /TN MeshUserTask\r\n');
child.stdin.write('SCHTASKS /DELETE /F /TN MeshUserTask\r\n');