diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 4b06479..917681e 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -3949,6 +3949,11 @@ void MeshAgent_AgentInstallerCTX_Finalizer(duk_context *ctx, void *user) } } +BOOL MeshAgent_PidWaiter(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void* user) +{ + ILibStopChain(chain); + return(FALSE); +} int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **param, int parseCommands) { int resetNodeId = 0; @@ -4567,6 +4572,18 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** } } +#ifdef WIN32 + if (ILibSimpleDataStore_Get(agentHost->masterDb, "exitPID", NULL, 0) > 0) + { + int pidLen = ILibSimpleDataStore_Get(agentHost->masterDb, "exitPID", ILibScratchPad, (int)sizeof(ILibScratchPad)); + HANDLE h = OpenProcess(SYNCHRONIZE, FALSE, (DWORD)atoi(ILibScratchPad)); + if (h != NULL) { ILibChain_AddWaitHandle(agentHost->chain, h, -1, MeshAgent_PidWaiter, agentHost); } + } + if (ILibSimpleDataStore_Get(agentHost->masterDb, "hideConsole", NULL, 0) > 0 && agentHost->meshCoreCtx != NULL) + { + duk_peval_string_noresult(agentHost->meshCoreCtx, "require('win-console').hide()"); + } +#endif ILibIPAddressMonitor_Create(agentHost->chain, MeshAgent_AgentMode_IPAddressChanged_Handler, agentHost); MeshServer_Connect(agentHost); diff --git a/meshservice/ServiceMain.c b/meshservice/ServiceMain.c index bdf9258..44a2ac4 100644 --- a/meshservice/ServiceMain.c +++ b/meshservice/ServiceMain.c @@ -1377,12 +1377,19 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP return (INT_PTR)TRUE; } - else if (LOWORD(wParam) == IDC_CONNECTBUTTON) { + else if (LOWORD(wParam) == IDC_CONNECTBUTTON) + { + // + // Temporary Agent + // EnableWindow(GetDlgItem(hDlg, IDC_INSTALLBUTTON), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_UNINSTALLBUTTON), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_CONNECTBUTTON), FALSE); SetWindowTextA(GetDlgItem(hDlg, IDC_STATUSTEXT), "Running as temporary agent"); - CreateThread(NULL, 0, &StartTempAgent, NULL, 0, NULL); + + DWORD pid = GetCurrentProcessId(); + sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "connect --disableUpdate=1 --hideConsole=1 --exitPID=%u", pid); + RunAsAdmin(ILibScratchPad, IsAdmin() == TRUE); return (INT_PTR)TRUE; } break;