1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

Added UAC elevation for Temporary Agent when run from connect button on installer UI

This commit is contained in:
Bryan Roe
2020-05-17 23:07:11 -07:00
parent 66122d43c1
commit 19fb0163d5
2 changed files with 26 additions and 2 deletions

View File

@@ -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);

View File

@@ -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;