1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-22 19:23:31 +00:00

Added work around for older versions of SCHTASK, like in Windows 7, when execPath includes spaces. This fixes spawning user terminal session, among other things.

This commit is contained in:
Bryan Roe
2020-04-06 09:26:55 -07:00
parent d25023e92b
commit 4bcb16c35a
2 changed files with 5 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -43,6 +43,7 @@ function dispatch(options)
{ {
} }
} }
var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64'); var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64');
ret._ipc2.once('connection', function onConnect(s) ret._ipc2.once('connection', function onConnect(s)
{ {
@@ -86,19 +87,19 @@ function dispatch(options)
if (options.user) if (options.user)
{ {
child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /RU ' + options.user + ' /TR "' + process.execPath + ' -b64exec ' + str + '"\r\n'); child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /RU ' + options.user + ' /TR "\\"' + process.execPath + '\\" -b64exec ' + str + '"\r\n');
} }
else else
{ {
if (require('user-sessions').getProcessOwnerName(process.pid).tsid == 0) if (require('user-sessions').getProcessOwnerName(process.pid).tsid == 0)
{ {
// LocalSystem // LocalSystem
child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /RU SYSTEM /TR "' + process.execPath + ' -b64exec ' + str + '"\r\n'); child.stdin.write('SCHTASKS /CREATE /F /TN MeshUserTask /SC ONCE /ST 00:00 /RU SYSTEM /TR "\\"' + process.execPath + '\\" -b64exec ' + str + '"\r\n');
} }
else else
{ {
// Running as logged in user // 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 /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 /RUN /TN MeshUserTask\r\n');
@@ -106,7 +107,6 @@ function dispatch(options)
child.stdin.write('exit\r\n'); child.stdin.write('exit\r\n');
child.waitExit(); child.waitExit();
return (ret); return (ret);
} }