Added check, so Windows Agents will make sure they can run in Safe Mode

Bryan Roe committed Jan 21, 2020 at 15:44 UTC 2973c701197baf68e16faa9531a8593e1be9170a
1 file changed +7 -1
agents/meshcore.js
+7 -1
@@ -39,11 +39,17 @@ var MESHRIGHT_LIMITEDINPUT = 4096;
39
40 function createMeshCore(agent) {
41 var obj = {};
42 - if (process.platform == 'win32' && require('user-sessions').isRoot()) {
42 + if (process.platform == 'win32' && require('user-sessions').isRoot())
43 + {
44 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
45 var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
46 try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (x) { }
47 if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (x2) { } }
48 +
49 + // Check to see if we are the Installed Mesh Agent Service, if we are, make sure we can run in Safe Mode
50 + var meshCheck = false;
51 + try { meshCheck = require('service-manager').manager.getService('Mesh Agent').isMe(); } catch (mce) { }
52 + if (meshCheck && require('win-bcd').isSafeModeService && !require('win-bcd').isSafeModeService('Mesh Agent')) { require('win-bcd').enableSafeModeService('Mesh Agent'); }
53 }
54
55 if (process.platform == 'darwin' && !process.versions) {