1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-02-21 03:43:33 +00:00

Update documentation

This commit is contained in:
Bryan Roe
2022-10-06 15:43:06 -07:00
parent 705aac16ad
commit 0a1fa58d4d
2 changed files with 71 additions and 1 deletions

View File

@@ -14,6 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//
// win-bcd interacts with Windows BCD to be able to modify Safe Mode related settings
//
//
// This function uses the Windows System Utility 'bcdedit' to fetch metadata about the bootloader configuration
//
function getKeys()
{
var ret = {};
@@ -25,6 +33,9 @@ function getKeys()
var lines = child.stdout.str.trim().split('\r\n');
lines.shift(); lines.shift();
//
// Enumerate each line entry, and parse out the key/value pair
//
for (var i in lines)
{
var tokens = lines[i].split(' ');
@@ -34,10 +45,18 @@ function getKeys()
}
return (ret);
}
//
// Returns the value associated with the specified key
//
function getKey(key)
{
return (this.getKeys()[key]);
}
//
// Using the Windows System Utility 'bcdedit', set a key/value to the current bootloader configuration
//
function setKey(key, value)
{
var child = require('child_process').execFile(process.env['windir'] + "\\System32\\bcdedit.exe", ['bcdedit', '/set', '{current}', key, value]);
@@ -45,6 +64,10 @@ function setKey(key, value)
child.stderr.on('data', function () { });
child.waitExit();
}
//
// Using the Windows System Utility 'bcdedit', delete a key/value pair from the current bootloader configuration
//
function deleteKey(key)
{
var child = require('child_process').execFile(process.env['windir'] + "\\System32\\bcdedit.exe", ['bcdedit', '/deletevalue', '{current}', key]);
@@ -53,10 +76,17 @@ function deleteKey(key)
child.waitExit();
}
//
// Add the specified service name, to Window's list of services allowed to run in SafeMode with Networking
//
function enableSafeModeService(serviceName)
{
require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Control\\Safeboot\\Network\\' + serviceName, null, 'Service');
}
//
// Query if the specified service name is allowed to run in Safe Mode
//
function isSafeModeService(serviceName)
{
var reg = require('win-registry');
@@ -64,6 +94,10 @@ function isSafeModeService(serviceName)
try { key = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Control\\Safeboot\\Network\\' + serviceName); } catch (qke) { }
return (key.default == 'Service');
}
//
// Remove the specified service from the allowed list of services that can run in Safe Mode
//
function disableSafeModeService(serviceName)
{
try
@@ -75,6 +109,9 @@ function disableSafeModeService(serviceName)
}
}
//
// Use the windows system utility, 'shutdown' to restart the PC immediately
//
function restart(delay)
{
var child = require('child_process').execFile(process.env['windir'] + "\\System32\\shutdown.exe", ['shutdown', '/r', '/t', delay!=null?delay.toString():'0']);
@@ -85,6 +122,9 @@ function restart(delay)
if (require('_GenericMarshal').PointerSize == 4 && require('os').arch() == 'x64')
{
//
// 32 bit agent running on 64 bit windows, we do not expose BCD functions, because bcdedit does not work from a 32 bit process on 64 bit windows
//
module.exports =
{
enableSafeModeService: enableSafeModeService,
@@ -99,6 +139,9 @@ else
disableSafeModeService: disableSafeModeService, getKey: getKey, restart: restart, isSafeModeService: isSafeModeService
};
//
// Query what the next boot mode is currently set to... NORMAL, SAFEMODE, or SAFEMODE w/Networking
//
Object.defineProperty(module.exports, "bootMode",
{
get: function ()