mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-17 16:53:13 +00:00
1. Updated -fullinstall -install -fulluninstall -install to use agent-installer
2. Fixed DPI awareness on Installer Dialog Box
This commit is contained in:
@@ -3963,11 +3963,28 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
if (agentHost->masterDb != NULL) { ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1)); }
|
if (agentHost->masterDb != NULL) { ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1)); }
|
||||||
++ixr;
|
++ixr;
|
||||||
}
|
}
|
||||||
if (strcmp("-finstall", param[ri]) == 0)
|
if (strcmp("-finstall", param[ri]) == 0 || strcmp("-fullinstall", param[ri]) == 0)
|
||||||
{
|
{
|
||||||
installFlag = 1;
|
installFlag = 1;
|
||||||
}
|
}
|
||||||
|
if (strcmp("-install", param[ri]) == 0)
|
||||||
|
{
|
||||||
|
installFlag = 5;
|
||||||
|
if (agentHost->masterDb != NULL)
|
||||||
|
{
|
||||||
|
ILibSimpleDataStore_Cached(agentHost->masterDb, "_localService", 13, "1", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0)
|
if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0)
|
||||||
|
{
|
||||||
|
installFlag = 2;
|
||||||
|
if (agentHost->masterDb != NULL)
|
||||||
|
{
|
||||||
|
ILibSimpleDataStore_Cached(agentHost->masterDb, "_deleteData", 11, "1", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (strcmp("-uninstall", param[ri]) == 0)
|
||||||
{
|
{
|
||||||
installFlag = 2;
|
installFlag = 2;
|
||||||
}
|
}
|
||||||
@@ -3989,6 +4006,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
switch (installFlag)
|
switch (installFlag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
case 5:
|
||||||
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, NULL, 0);
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, NULL, 0);
|
||||||
buf = (char*)ILibMemory_SmartAllocate(bufLen);
|
buf = (char*)ILibMemory_SmartAllocate(bufLen);
|
||||||
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, buf, bufLen);
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, buf, bufLen);
|
||||||
@@ -4009,10 +4027,15 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
return(1);
|
return(1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, NULL, 0);
|
||||||
|
buf = (char*)ILibMemory_SmartAllocate(bufLen);
|
||||||
|
bufLen = ILibSimpleDataStore_Cached_GetJSONEx(agentHost->masterDb, buf, bufLen);
|
||||||
|
|
||||||
duk_eval_string(ctxx, "require('agent-installer');");
|
duk_eval_string(ctxx, "require('agent-installer');");
|
||||||
duk_get_prop_string(ctxx, -1, "fullUninstall");
|
duk_get_prop_string(ctxx, -1, "fullUninstall");
|
||||||
duk_swap_top(ctxx, -2);
|
duk_swap_top(ctxx, -2);
|
||||||
if (duk_pcall_method(ctxx, 0) != 0)
|
duk_push_string(ctxx, buf);
|
||||||
|
if (duk_pcall_method(ctxx, 1) != 0)
|
||||||
{
|
{
|
||||||
if (strcmp(duk_safe_to_string(ctxx, -1), "Process.exit() forced script termination") != 0)
|
if (strcmp(duk_safe_to_string(ctxx, -1), "Process.exit() forced script termination") != 0)
|
||||||
{
|
{
|
||||||
@@ -4020,6 +4043,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
duk_pop(ctxx);
|
duk_pop(ctxx);
|
||||||
|
ILibMemory_Free(buf);
|
||||||
return(1);
|
return(1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ int ClearWindowsFirewall(wchar_t* processname);
|
|||||||
#include <WtsApi32.h>
|
#include <WtsApi32.h>
|
||||||
|
|
||||||
TCHAR* serviceFile = TEXT("Mesh Agent");
|
TCHAR* serviceFile = TEXT("Mesh Agent");
|
||||||
TCHAR* serviceFileOld = TEXT("Mesh Agent v2");
|
|
||||||
TCHAR* serviceName = TEXT("Mesh Agent background service");
|
TCHAR* serviceName = TEXT("Mesh Agent background service");
|
||||||
TCHAR* serviceDesc = TEXT("Remote monitoring and management service.");
|
TCHAR* serviceDesc = TEXT("Remote monitoring and management service.");
|
||||||
|
|
||||||
@@ -376,134 +375,6 @@ int RunService(int argc, char* argv[])
|
|||||||
return StartServiceCtrlDispatcher( serviceTable );
|
return StartServiceCtrlDispatcher( serviceTable );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL InstallService()
|
|
||||||
{
|
|
||||||
SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CREATE_SERVICE );
|
|
||||||
SERVICE_DESCRIPTION sd;
|
|
||||||
SERVICE_DELAYED_AUTO_START_INFO as;
|
|
||||||
SERVICE_FAILURE_ACTIONS fa;
|
|
||||||
SC_ACTION failactions[3];
|
|
||||||
BOOL r = FALSE;
|
|
||||||
|
|
||||||
if ( serviceControlManager )
|
|
||||||
{
|
|
||||||
char path[1024];
|
|
||||||
if (GetModuleFileName( 0, (LPTSTR)path, 1024) > 0)
|
|
||||||
{
|
|
||||||
// Install the service
|
|
||||||
SC_HANDLE service = CreateService(
|
|
||||||
serviceControlManager,
|
|
||||||
serviceFile,
|
|
||||||
serviceName,
|
|
||||||
SERVICE_ALL_ACCESS,
|
|
||||||
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
|
|
||||||
SERVICE_AUTO_START,
|
|
||||||
SERVICE_ERROR_IGNORE,
|
|
||||||
(LPCTSTR)path,
|
|
||||||
0, 0, 0, 0, 0 );
|
|
||||||
|
|
||||||
if (service)
|
|
||||||
{
|
|
||||||
// Update the service description
|
|
||||||
sd.lpDescription = serviceDesc;
|
|
||||||
ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sd);
|
|
||||||
|
|
||||||
// Update the service auto-start
|
|
||||||
as.fDelayedAutostart = FALSE;
|
|
||||||
ChangeServiceConfig2(service, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &as);
|
|
||||||
|
|
||||||
// Update the faliure action
|
|
||||||
failactions[0].Type = SC_ACTION_RESTART;
|
|
||||||
failactions[0].Delay = 60000; // Wait 1 minutes before faliure restart (milliseconds)
|
|
||||||
failactions[1].Type = SC_ACTION_RESTART;
|
|
||||||
failactions[1].Delay = 60000; // Wait 1 minutes before faliure restart (milliseconds)
|
|
||||||
failactions[2].Type = SC_ACTION_RESTART;
|
|
||||||
failactions[2].Delay = 60000;
|
|
||||||
memset(&fa, 0, sizeof(SERVICE_FAILURE_ACTIONS));
|
|
||||||
fa.dwResetPeriod = 86400; // After 1 days, reset the faliure counters (seconds)
|
|
||||||
fa.cActions = 3;
|
|
||||||
fa.lpsaActions = failactions;
|
|
||||||
r = ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &fa);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseServiceHandle( service );
|
|
||||||
#ifdef _DEBUG
|
|
||||||
//ILIBMESSAGE("Mesh service installed successfully");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
if(GetLastError() == ERROR_SERVICE_EXISTS)
|
|
||||||
{
|
|
||||||
ILIBMESSAGE("Mesh service already exists.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ILIBMESSAGE("Mesh service was not Installed Successfully.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CloseServiceHandle( serviceControlManager );
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int UninstallService(TCHAR* serviceName)
|
|
||||||
{
|
|
||||||
int r = 0;
|
|
||||||
SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CONNECT);
|
|
||||||
|
|
||||||
if (serviceControlManager)
|
|
||||||
{
|
|
||||||
SC_HANDLE service = OpenService( serviceControlManager, serviceName, SERVICE_QUERY_STATUS | DELETE );
|
|
||||||
if (service)
|
|
||||||
{
|
|
||||||
SERVICE_STATUS serviceStatusEx;
|
|
||||||
if ( QueryServiceStatus( service, &serviceStatusEx ) )
|
|
||||||
{
|
|
||||||
if ( serviceStatusEx.dwCurrentState == SERVICE_STOPPED )
|
|
||||||
{
|
|
||||||
if (DeleteService(service))
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
//ILIBMESSAGE("Mesh service removed successfully");
|
|
||||||
#endif
|
|
||||||
r = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
DWORD dwError = GetLastError();
|
|
||||||
if(dwError == ERROR_ACCESS_DENIED) {
|
|
||||||
ILIBMESSAGE("Access denied while trying to remove mesh service");
|
|
||||||
}
|
|
||||||
else if(dwError == ERROR_INVALID_HANDLE) {
|
|
||||||
ILIBMESSAGE("Handle invalid while trying to remove mesh service");
|
|
||||||
}
|
|
||||||
else if(dwError == ERROR_SERVICE_MARKED_FOR_DELETE) {
|
|
||||||
ILIBMESSAGE("Mesh service already marked for deletion");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = 2;
|
|
||||||
#ifdef _DEBUG
|
|
||||||
ILIBMESSAGE("Mesh service is still running");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CloseServiceHandle( service );
|
|
||||||
}
|
|
||||||
CloseServiceHandle( serviceControlManager );
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SERVICE_STOPPED 1 The service is not running.
|
// SERVICE_STOPPED 1 The service is not running.
|
||||||
// SERVICE_START_PENDING 2 The service is starting.
|
// SERVICE_START_PENDING 2 The service is starting.
|
||||||
// SERVICE_STOP_PENDING 3 The service is stopping.
|
// SERVICE_STOP_PENDING 3 The service is stopping.
|
||||||
@@ -654,7 +525,9 @@ int wmain(int argc, char* wargv[])
|
|||||||
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wargv[argvi], -1, argv[argvi], argvsz, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wargv[argvi], -1, argv[argvi], argvsz, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0 || strcasecmp(argv[1], "-fulluninstall") == 0))
|
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0 ||
|
||||||
|
strcasecmp(argv[1], "-fulluninstall") == 0 || strcasecmp(argv[1], "-fullinstall") == 0 ||
|
||||||
|
strcasecmp(argv[1], "-install")==0 || strcasecmp(argv[1], "-uninstall") == 0))
|
||||||
{
|
{
|
||||||
argv[argc] = argv[1];
|
argv[argc] = argv[1];
|
||||||
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
||||||
@@ -977,69 +850,6 @@ int wmain(int argc, char* wargv[])
|
|||||||
else if (r == 2) { printf("Mesh agent failed to stop"); }
|
else if (r == 2) { printf("Mesh agent failed to stop"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (argc > 1 && strcasecmp(argv[1], "-install") == 0)
|
|
||||||
{
|
|
||||||
// Setup the service
|
|
||||||
StopService(serviceFile);
|
|
||||||
UninstallService(serviceFile);
|
|
||||||
UninstallService(serviceFileOld);
|
|
||||||
if (InstallService() == TRUE) { printf("Mesh agent installed"); } else { printf("Failed to install mesh agent"); }
|
|
||||||
|
|
||||||
#ifndef _MINCORE
|
|
||||||
// Setup the Windows firewall
|
|
||||||
if (GetModuleFileNameW(NULL, str, _MAX_PATH) > 5)
|
|
||||||
{
|
|
||||||
ClearWindowsFirewall(str);
|
|
||||||
if (SetupWindowsFirewall(str) != 0)
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
ILIBMESSAGE("Firewall rules added successfully");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
ILIBMESSAGE("Unable to add firewall rules");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (argc > 1 && ((strcasecmp(argv[1], "-remove") == 0) || (strcasecmp(argv[1], "-uninstall") == 0)))
|
|
||||||
{
|
|
||||||
// Ask the service manager to stop the service
|
|
||||||
StopService(serviceFile);
|
|
||||||
|
|
||||||
// Remove the service
|
|
||||||
UninstallService(serviceFileOld);
|
|
||||||
i = UninstallService(serviceFile);
|
|
||||||
if (i == 0) { printf("Failed to uninstall mesh agent"); }
|
|
||||||
else if (i == 1) { printf("Mesh agent uninstalled"); }
|
|
||||||
else if (i == 2) { printf("Mesh agent still running"); }
|
|
||||||
|
|
||||||
#ifndef _MINCORE
|
|
||||||
// Remove the MeshAgent registry keys
|
|
||||||
RegDeleteKey(HKEY_LOCAL_MACHINE, "Software\\Open Source\\MeshAgent2");
|
|
||||||
RegDeleteKey(HKEY_CURRENT_USER, "Software\\Open Source\\MeshAgent2");
|
|
||||||
|
|
||||||
// Cleanup the firewall rules
|
|
||||||
if (GetModuleFileNameW( NULL, str, _MAX_PATH ) > 5)
|
|
||||||
{
|
|
||||||
if (ClearWindowsFirewall(str) != 0)
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
ILIBMESSAGE("Firewall rules removed successfully");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
ILIBMESSAGE("Unable to remove firewall rules");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#ifdef _MINCORE
|
#ifdef _MINCORE
|
||||||
else if (argc > 1 && memcmp(argv[1], "-update:", 8) == 0)
|
else if (argc > 1 && memcmp(argv[1], "-update:", 8) == 0)
|
||||||
{
|
{
|
||||||
@@ -1177,8 +987,6 @@ int wmain(int argc, char* wargv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UninstallService(serviceFileOld);
|
|
||||||
|
|
||||||
// See if we are running as a service
|
// See if we are running as a service
|
||||||
if (RunService(argc, argv) == 0 && GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
|
if (RunService(argc, argv) == 0 && GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -18,9 +18,9 @@ limitations under the License.
|
|||||||
function installService(params)
|
function installService(params)
|
||||||
{
|
{
|
||||||
process.stdout.write('...Installing service');
|
process.stdout.write('...Installing service');
|
||||||
try
|
|
||||||
{
|
|
||||||
require('service-manager').manager.installService(
|
var options =
|
||||||
{
|
{
|
||||||
name: process.platform == 'win32' ? 'Mesh Agent' : 'meshagent',
|
name: process.platform == 'win32' ? 'Mesh Agent' : 'meshagent',
|
||||||
target: process.platform == 'win32' ? 'MeshAgent' : 'meshagent',
|
target: process.platform == 'win32' ? 'MeshAgent' : 'meshagent',
|
||||||
@@ -28,7 +28,29 @@ function installService(params)
|
|||||||
servicePath: process.execPath,
|
servicePath: process.execPath,
|
||||||
startType: 'AUTO_START',
|
startType: 'AUTO_START',
|
||||||
parameters: params
|
parameters: params
|
||||||
});
|
};
|
||||||
|
var i;
|
||||||
|
if ((i=params.indexOf('--_localService="1"'))>=0)
|
||||||
|
{
|
||||||
|
// install in place
|
||||||
|
options.parameters.splice(i, 1);
|
||||||
|
options.installInPlace = true;
|
||||||
|
}
|
||||||
|
for (i = 0; i < options.parameters.length; ++i)
|
||||||
|
{
|
||||||
|
if(options.parameters[i].startsWith('--installPath='))
|
||||||
|
{
|
||||||
|
options.installPath = options.parameters[i].split('=')[1];
|
||||||
|
if (options.installPath.startsWith('"')) { options.installPath = options.installPath.substring(1, options.installPath.length - 1); }
|
||||||
|
options.parameters.splice(i, 1);
|
||||||
|
options.installInPlace = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
require('service-manager').manager.installService(options);
|
||||||
process.stdout.write(' [DONE]\n');
|
process.stdout.write(' [DONE]\n');
|
||||||
}
|
}
|
||||||
catch(sie)
|
catch(sie)
|
||||||
@@ -154,7 +176,7 @@ function uninstallService3(params)
|
|||||||
process.stdout.write(' [ERROR]\n');
|
process.stdout.write(' [ERROR]\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params != null)
|
if (params != null && !params.includes('_stop'))
|
||||||
{
|
{
|
||||||
installService(params);
|
installService(params);
|
||||||
}
|
}
|
||||||
@@ -167,12 +189,53 @@ function uninstallService3(params)
|
|||||||
function uninstallService2(params)
|
function uninstallService2(params)
|
||||||
{
|
{
|
||||||
var secondaryagent = false;
|
var secondaryagent = false;
|
||||||
|
var i;
|
||||||
|
var dataFolder = null;
|
||||||
|
var appPrefix = null;
|
||||||
|
|
||||||
|
if (params && params.includes('--_deleteData="1"'))
|
||||||
|
{
|
||||||
|
for (i = 0; i < params.length; ++i)
|
||||||
|
{
|
||||||
|
if (params[i].startsWith('_workingDir='))
|
||||||
|
{
|
||||||
|
dataFolder = params[i].split('=')[1];
|
||||||
|
if (dataFolder.startsWith('"')) { dataFolder = dataFolder.substring(1, dataFolder.length - 1); }
|
||||||
|
}
|
||||||
|
if (params[i].startsWith('_appPrefix='))
|
||||||
|
{
|
||||||
|
appPrefix = params[i].split('=')[1];
|
||||||
|
if (appPrefix.startsWith('"')) { appPrefix = appPrefix.substring(1, appPrefix.length - 1); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process.stdout.write(' -> Uninstalling previous installation...');
|
process.stdout.write(' -> Uninstalling previous installation...');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
require('service-manager').manager.uninstallService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
require('service-manager').manager.uninstallService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
process.stdout.write(' [DONE]\n');
|
process.stdout.write(' [DONE]\n');
|
||||||
|
if (dataFolder && appPrefix)
|
||||||
|
{
|
||||||
|
process.stdout.write(' -> Deleting agent data...');
|
||||||
|
var child = require('child_process').execFile(process.platform == 'win32' ? (process.env['windir'] + '\\system32\\cmd.exe') : ('/bin/sh'), [process.platform == 'win32' ? 'cmd.exe' : 'sh']);
|
||||||
|
child.stdout.on('data', function (c) { });
|
||||||
|
child.stderr.on('data', function (c) { });
|
||||||
|
if (process.platform == 'win32')
|
||||||
|
{
|
||||||
|
child.stdin.write('cd /D ' + dataFolder + '\r\n');
|
||||||
|
child.stdin.write('erase ' + appPrefix + '.*\r\n');
|
||||||
|
child.stdin.write('exit\r\n');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child.stdin.write('cd ' + dataFolder + '\n');
|
||||||
|
child.stdin.write('rm ' + appPrefix + '.*\r\n');
|
||||||
|
child.stdin.write('exit\n');
|
||||||
|
}
|
||||||
|
child.waitExit();
|
||||||
|
process.stdout.write(' [DONE]\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
@@ -288,15 +351,23 @@ function serviceExists(loc, params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fullUninstall()
|
function fullUninstall(jsonString)
|
||||||
{
|
{
|
||||||
console.setDestination(console.Destinations.DISABLED);
|
console.setDestination(console.Destinations.DISABLED);
|
||||||
|
var parms = JSON.parse(jsonString);
|
||||||
|
parms.push('_stop');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process.stdout.write('...Checking for previous installation');
|
process.stdout.write('...Checking for previous installation');
|
||||||
var s = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
var s = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
var loc = s.appLocation();
|
var loc = s.appLocation();
|
||||||
|
var appPrefix = loc.split(process.platform == 'win32' ? '\\' : '/').pop();
|
||||||
|
if (process.platform == 'win32') { appPrefix = appPrefix.substring(0, appPrefix.length - 4); }
|
||||||
|
|
||||||
|
parms.push('_workingDir=' + s.appWorkingDirectory());
|
||||||
|
parms.push('_appPrefix=' + appPrefix);
|
||||||
|
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -304,7 +375,7 @@ function fullUninstall()
|
|||||||
process.stdout.write(' [NONE]\n');
|
process.stdout.write(' [NONE]\n');
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
serviceExists(loc, null);
|
serviceExists(loc, parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fullInstall(jsonString)
|
function fullInstall(jsonString)
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ function extractFileSource(filePath)
|
|||||||
return (typeof (filePath) == 'string' ? filePath : filePath.source);
|
return (typeof (filePath) == 'string' ? filePath : filePath.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function perpareFolders(folderPath)
|
||||||
|
{
|
||||||
|
var dlmtr = process.platform == 'win32' ? '\\' : '/';
|
||||||
|
|
||||||
|
var tokens = folderPath.split(dlmtr);
|
||||||
|
var path = null;
|
||||||
|
|
||||||
|
while (tokens.length>0)
|
||||||
|
{
|
||||||
|
path = (path == null ? tokens.shift() : (path + dlmtr + tokens.shift()));
|
||||||
|
if (path.indexOf(process.platform == 'win32' ? '\\' : '/') < 0) { continue; }
|
||||||
|
if (!require('fs').existsSync(path)) { require('fs').mkdirSync(path); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseServiceStatus(token)
|
function parseServiceStatus(token)
|
||||||
{
|
{
|
||||||
var j = {};
|
var j = {};
|
||||||
@@ -580,7 +595,7 @@ function serviceManager()
|
|||||||
blockSize += ((ptrSize - (blockSize % ptrSize)) % ptrSize);
|
blockSize += ((ptrSize - (blockSize % ptrSize)) % ptrSize);
|
||||||
var retVal = [];
|
var retVal = [];
|
||||||
for (var i = 0; i < servicesReturned.Deref(0, dbName._size).toBuffer().readUInt32LE(); ++i)
|
for (var i = 0; i < servicesReturned.Deref(0, dbName._size).toBuffer().readUInt32LE(); ++i)
|
||||||
{
|
{
|
||||||
var token = services.Deref(i * blockSize, blockSize);
|
var token = services.Deref(i * blockSize, blockSize);
|
||||||
var j = {};
|
var j = {};
|
||||||
j.name = token.Deref(0, ptrSize).Deref().Wide2UTF8;
|
j.name = token.Deref(0, ptrSize).Deref().Wide2UTF8;
|
||||||
@@ -1552,6 +1567,9 @@ function serviceManager()
|
|||||||
{
|
{
|
||||||
if (!options.target) { options.target = options.name; }
|
if (!options.target) { options.target = options.name; }
|
||||||
if (!options.displayName) { options.displayName = options.name; }
|
if (!options.displayName) { options.displayName = options.name; }
|
||||||
|
if (options.installPath) { if (!options.installPath.endsWith(process.platform == 'win32' ? '\\' : '/')) { options.installPath += (process.platform == 'win32' ? '\\' : '/'); } }
|
||||||
|
if (options.installPath && options.installInPlace) { throw ('Cannot specify both installPath and installInPlace'); }
|
||||||
|
if (process.platform != 'win32' && (options.installInPlace || options.installPath)) { throw ('Installation into non standard location is not supported on this platform'); }
|
||||||
|
|
||||||
if (process.platform == 'win32')
|
if (process.platform == 'win32')
|
||||||
{
|
{
|
||||||
@@ -1559,12 +1577,24 @@ function serviceManager()
|
|||||||
if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); }
|
if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); }
|
||||||
|
|
||||||
// Before we start, we need to copy the binary to the right place
|
// Before we start, we need to copy the binary to the right place
|
||||||
var folder = this.getServiceFolder();
|
var folder = options.installPath == null ? this.getServiceFolder() : options.installPath;
|
||||||
if (!require('fs').existsSync(folder)) { require('fs').mkdirSync(folder); }
|
if (folder.endsWith('\\')) { folder = folder.substring(0, folder.length - 1); }
|
||||||
if (!require('fs').existsSync(folder + '\\' + options.name)) { require('fs').mkdirSync(folder + '\\' + options.name); }
|
if (!options.installInPlace) { perpareFolders(folder + '\\' + options.name); }
|
||||||
if (options.servicePath == process.execPath) { options._isMeshAgent = true; }
|
if (options.servicePath == process.execPath) { options._isMeshAgent = true; }
|
||||||
|
|
||||||
|
if (!options.installInPlace)
|
||||||
|
{
|
||||||
require('fs').copyFileSync(options.servicePath, folder + '\\' + options.name + '\\' + options.target + '.exe');
|
require('fs').copyFileSync(options.servicePath, folder + '\\' + options.name + '\\' + options.target + '.exe');
|
||||||
options.servicePath = folder + '\\' + options.name + '\\' + options.target + '.exe';
|
options.servicePath = folder + '\\' + options.name + '\\' + options.target + '.exe';
|
||||||
|
if (!options.installPath) { options.installPath = folder + '\\' + options.name + '\\'; }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.servicePath = process.execPath;
|
||||||
|
options.installPath = process.execPath.split('\\');
|
||||||
|
options.installPath.pop();
|
||||||
|
options.installPath = options.installPath.join('\\') + '\\';
|
||||||
|
}
|
||||||
|
|
||||||
var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"', { wide: true });
|
var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"', { wide: true });
|
||||||
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
|
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
|
||||||
@@ -1631,19 +1661,16 @@ function serviceManager()
|
|||||||
if (options.files[i]._buffer)
|
if (options.files[i]._buffer)
|
||||||
{
|
{
|
||||||
console.log('writing ' + extractFileName(options.files[i]));
|
console.log('writing ' + extractFileName(options.files[i]));
|
||||||
require('fs').writeFileSync(folder + '\\' + options.name + '\\' + extractFileName(options.files[i]), options.files[i]._buffer);
|
require('fs').writeFileSync(options.installPath + extractFileName(options.files[i]), options.files[i]._buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log('copying ' + extractFileSource(options.files[i]));
|
console.log('copying ' + extractFileSource(options.files[i]));
|
||||||
require('fs').copyFileSync(extractFileSource(options.files[i]), folder + '\\' + options.name + '\\' + extractFileName(options.files[i]));
|
require('fs').copyFileSync(extractFileSource(options.files[i]), options.installPath + extractFileName(options.files[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (options.parameters)
|
if (options.parameters)
|
||||||
{
|
{
|
||||||
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
|
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
|
||||||
@@ -1670,19 +1697,19 @@ function serviceManager()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'DisplayName', options.displayName);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'DisplayName', options.displayName);
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'DisplayIcon', folder + '\\' + options.name + '\\' + options.target + '.exe');
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'DisplayIcon', options.servicePath);
|
||||||
if (options.publisher) { reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'Publisher', options.publisher); }
|
if (options.publisher) { reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'Publisher', options.publisher); }
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'InstallLocation', folder + '\\' + options.name);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'InstallLocation', options.installPath);
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'EstimatedSize', Math.floor(require('fs').statSync(folder + '\\' + options.name + '\\' + options.target + '.exe').size / 1024));
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'EstimatedSize', Math.floor(require('fs').statSync(options.servicePath).size / 1024));
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoModify', 0x1);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoModify', 0x1);
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoRepair', 0x1);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoRepair', 0x1);
|
||||||
if (options.name == 'Mesh Agent')
|
if (options.name == 'Mesh Agent')
|
||||||
{
|
{
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -funinstall');
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', options.servicePath + ' -funinstall');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -b64exec ' + script);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', options.servicePath + ' -b64exec ' + script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (xx)
|
catch (xx)
|
||||||
|
|||||||
Reference in New Issue
Block a user