1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-11 13:53:37 +00:00

1. Added 'global' polyfill

2. Updated service-manager in Native and JS, to add '_installedBy' on Windows
This commit is contained in:
Bryan Roe
2019-11-20 14:41:22 -08:00
parent e68d0cc7c5
commit bca47688ff
4 changed files with 186 additions and 128 deletions

View File

@@ -108,6 +108,27 @@ BOOL RunAsAdmin(char* args) {
return FALSE;
}
void UpdateOwnerData()
{
WCHAR str[_MAX_PATH];
DWORD strLen;
strLen = GetModuleFileNameW(NULL, str, _MAX_PATH);
int exePathLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)str, -1, NULL, 0, NULL, NULL);
char *exePath = (char*)ILibMemory_SmartAllocate(exePathLen);
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)str, -1, exePath, exePathLen, NULL, NULL);
void *chain = ILibCreateChain();
duk_context *ctx = ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, chain, NULL, NULL, exePath, NULL, NULL, NULL);
duk_peval_string_noresult(ctx, "global._noMessagePump=true;var key=require('win-registry').usernameToUserKey(require('user-sessions').getProcessOwnerName(process.pid).name);var reg=require('win-registry');reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\\\CurrentControlSet\\\\Services\\\\Mesh Agent', '_InstalledBy', key);");
duk_destroy_heap(ctx);
ILibChain_DestroyEx(chain);
ILibMemory_Free(exePath);
}
DWORD WINAPI ServiceControlHandler( DWORD controlCode, DWORD eventType, void *eventData, void* eventContext )
{
switch (controlCode)
@@ -874,6 +895,7 @@ void fullinstall(int uninstallonly, char* proxy, int proxylen, char* tag, int ta
// Add the uninstall icon in the control panel
AddUninstallIcon();
UpdateOwnerData();
/*
#if defined(_LINKVM)

File diff suppressed because one or more lines are too long

View File

@@ -618,6 +618,21 @@ function serviceManager()
}
}
});
Object.defineProperty(retVal, 'installedBy',
{
get: function()
{
var reg = require('win-registry');
try
{
return(reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + this.name, '_InstalledBy'));
}
catch(xx)
{
return (null);
}
}
});
if (retVal.status.state != 'UNKNOWN')
{
require('events').EventEmitter.call(retVal);
@@ -1532,6 +1547,7 @@ function serviceManager()
if (process.platform == 'win32')
{
var reg = require('win-registry');
if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); }
// Before we start, we need to copy the binary to the right place
@@ -1616,13 +1632,24 @@ function serviceManager()
}
}
}
if (options.parameters)
{
var reg = require('win-registry');
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
imagePath += (' ' + options.parameters.join(' '));
reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath', imagePath);
}
try
{
reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, '_InstalledBy', reg.usernameToUserKey(require('user-sessions').getProcessOwnerName(process.pid).name));
}
catch (xx)
{
}
}
if (process.platform == 'freebsd')
{

View File

@@ -320,7 +320,8 @@ function UserSessions()
return (retVal);
};
if (!global._noMessagePump)
{
// We need to spin up a message pump, and fetch a window handle
var message_pump = require('win-message-pump');
this._messagepump = new message_pump({ filter: WM_WTSSESSION_CHANGE }); this._messagepump.parent = this;
@@ -344,10 +345,10 @@ function UserSessions()
});
this._messagepump.on('message', function (msg)
{
switch(msg.message)
switch (msg.message)
{
case WM_WTSSESSION_CHANGE:
switch(msg.wparam)
switch (msg.wparam)
{
case WTS_SESSION_LOCK:
this.parent.enumerateUsers().then(function (users)
@@ -368,7 +369,7 @@ function UserSessions()
}
break;
case WM_POWERBROADCAST:
switch(msg.wparam)
switch (msg.wparam)
{
default:
console.log('WM_POWERBROADCAST [UNKNOWN wparam]: ' + msg.wparam);
@@ -388,10 +389,10 @@ function UserSessions()
case PBT_POWERSETTINGCHANGE:
var lparam = this.parent._marshal.CreatePointer(Buffer.from(msg.lparam_hex, 'hex'));
var data = lparam.Deref(20, lparam.Deref(16, 4).toBuffer().readUInt32LE(0)).toBuffer();
switch(lparam.Deref(0, 16).toBuffer().toString('hex'))
switch (lparam.Deref(0, 16).toBuffer().toString('hex'))
{
case GUID_ACDC_POWER_SOURCE.Deref(0, 16).toBuffer().toString('hex'):
switch(data.readUInt32LE(0))
switch (data.readUInt32LE(0))
{
case 0:
require('power-monitor').emit('acdc', 'AC');
@@ -408,7 +409,7 @@ function UserSessions()
require('power-monitor').emit('batteryLevel', data.readUInt32LE(0));
break;
case GUID_CONSOLE_DISPLAY_STATE.Deref(0, 16).toBuffer().toString('hex'):
switch(data.readUInt32LE(0))
switch (data.readUInt32LE(0))
{
case 0:
require('power-monitor').emit('display', 'OFF');
@@ -430,6 +431,7 @@ function UserSessions()
}
});
}
}
else if(process.platform == 'linux' || process.platform == 'freebsd')
{
if (process.platform == 'linux')