wait_for_existing_process stops more than one service

wait_for_existing_process stops more than one service

Postby Chrispy » 2019-04-10 08:40

Hi Rudi,

The new function wait_for_existing_process(); in service.cpp monitor_sessions_RDP hangs when more than one winvnc Service is running. I commented it out and everything runs as before.
Do we need this function?
What purpose does it provide?
Is there a Chance that the "Global\\SessionEventUltra" Name can be based on session id or something else, i.e. Parameter handed over from starting process?

Thanks,
Chris
User avatar
Chrispy
40
40
 
Posts: 93
Joined: 2018-07-11 09:06

Re: wait_for_existing_process stops more than one service

Postby Rudi De Vos » 2019-04-10 20:56

That isn't a new function it existed already for years.

hShutdownEvent: winvnc service set this to tell winvnc.exe to stop

1)
net stop uvnc_service, you also stop the winvnc running in the user desktop.
Without, the service can't stop the desktop part.
2)
If the service detect a desktop switch, he stops winvnc and restart it in the new desktop
Rudi De Vos
Admin & Developer
Admin & Developer
 
Posts: 5898
Joined: 2004-04-23 10:21

Re: wait_for_existing_process stops more than one service

Postby Chrispy » 2019-04-11 05:45

ok, well then it Needs more in the Name "Global\\SessionEventUltra", so that it and the process that it creates get monitored and not all instances of winvnc Server.
User avatar
Chrispy
40
40
 
Posts: 93
Joined: 2018-07-11 09:06

Re: wait_for_existing_process stops more than one service

Postby Chrispy » 2019-04-11 07:22

I have a function that I wrote to get the parent winvnc.exe pid that we could use to create all the global event names for Services. The Service could CreateEvent names with it's PID and the children would also create the global Event names from the parent pid, and both parent and child can use These to communicate.

What do you think?

Code: Select all
#include <tlhelp32.h>

DWORD GetParentWinVNCPID()
{
    int pid = -1;
    DWORD ppid = 0;
    HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (h == INVALID_HANDLE_VALUE)
    {
        return 0;
    }
    PROCESSENTRY32 pe = { 0 };
    pe.dwSize = sizeof(PROCESSENTRY32);

    //assume first arg is the PID to get the PPID for, or use own PID
    pid = GetCurrentProcessId();

    if (Process32First(h, &pe)) {
        do {
            if (pe.th32ProcessID == pid ) {
                printf("PID: %i; PPID: %i\n", pid, pe.th32ParentProcessID);
                ppid = pe.th32ParentProcessID;
                break;
            }
        } while (Process32Next(h, &pe));
    }

    if (ppid)
    {
        if (Process32First(h, &pe)) {
            do {
                if (pe.th32ProcessID == ppid) {
                    if (_stricmp(pe.szExeFile, "winvnc.exe") != 0)
                    {
                        ppid = 0;
                    }
                    break;
                }
            } while (Process32Next(h, &pe));
        }
    }

    CloseHandle(h);

    return ppid;
}
User avatar
Chrispy
40
40
 
Posts: 93
Joined: 2018-07-11 09:06

Re: wait_for_existing_process stops more than one service

Postby Chrispy » 2019-04-11 12:33

ok, so using the above function, set the Event names like this. I have tested and it works, should I check it in?

Code: Select all
winvnc.cpp

void SetEventNames()
{
    DWORD ppid = GetParentWinVNCPID();
    if (!ppid)
    {
        ppid = GetCurrentProcessId(); 
    }

    sprintf(g_szGlbSessEvt, "Global\\SessionEvent_%d", ppid);
    sprintf(g_szGlbSessEvtUltra, "Global\\SessionEventUltra_%d", ppid);
    sprintf(g_szGlbSessEvtCad, "Global\\SessionEventCad_%d", ppid);
    sprintf(g_szGlbSessEvtPreConnect, "Global\\SessionEventPreConnect_%d", ppid);
    sprintf(g_szGlbSessUltraPreConnect, "Global\\SessionUltraPreConnect_%d", ppid);
}
in Service.cpp:

        hEvent = CreateEvent(NULL, FALSE, FALSE, g_szGlbSessEvtUltra);
   hEventcad = CreateEvent(NULL, FALSE, FALSE, g_szGlbSessEvtCad);
   hEventPreConnect = CreateEvent(NULL, FALSE, FALSE, g_szGlbSessEvtPreConnect);
   hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(int), g_szGlbSessUltraPreConnect);

void wait_for_existing_process()
{
#ifdef _DEBUG
        OutputDebugString("Checking for preexisting tray icon\n");
#endif
    while ((hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, g_szGlbSessEvtUltra)) != NULL) {
       SetEvent(hEvent); // signal tray icon to shut down
        CloseHandle(hEvent);

#ifdef _DEBUG
        OutputDebugString("Waiting for existing tray icon to exit\n");
#endif
        Sleep(1000);
    }
}
User avatar
Chrispy
40
40
 
Posts: 93
Joined: 2018-07-11 09:06

Re: wait_for_existing_process stops more than one service

Postby Rudi De Vos » 2019-04-14 15:06

please commit, i will verify it later.
Rudi De Vos
Admin & Developer
Admin & Developer
 
Posts: 5898
Joined: 2004-04-23 10:21


Return to 1.2.2.x

Who is online

Users browsing this forum: No registered users and 1 guest