Update: UltraVNC 1.4.3.6 and UltraVNC SC 1.4.3.6: https://forum.uvnc.com/viewtopic.php?t=37885
Important: Please update to latest version before to create a reply, a topic or an issue: https://forum.uvnc.com/viewtopic.php?t=37864

Join us on social networks and share our announcements:
- Website: https://uvnc.com/
- GitHub: https://github.com/ultravnc
- Mastodon: https://mastodon.social/@ultravnc
- Facebook: https://www.facebook.com/ultravnc1
- X/Twitter: https://x.com/ultravnc1
- Reddit community: https://www.reddit.com/r/ultravnc
- OpenHub: https://openhub.net/p/ultravnc

wait_for_existing_process stops more than one service

Post Reply
User avatar
Chrispy
40
40
Posts: 103
Joined: 2018-07-11 09:06
Contact:

wait_for_existing_process stops more than one service

Post by Chrispy »

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
Opc Servers: http://www.wowbms.com/index.php/opc-servers
Wow Building & Energy Management System: http://www.wowbms.com/index.php
User avatar
Rudi De Vos
Admin & Developer
Admin & Developer
Posts: 6863
Joined: 2004-04-23 10:21
Contact:

Re: wait_for_existing_process stops more than one service

Post by Rudi De Vos »

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
User avatar
Chrispy
40
40
Posts: 103
Joined: 2018-07-11 09:06
Contact:

Re: wait_for_existing_process stops more than one service

Post by Chrispy »

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.
Opc Servers: http://www.wowbms.com/index.php/opc-servers
Wow Building & Energy Management System: http://www.wowbms.com/index.php
User avatar
Chrispy
40
40
Posts: 103
Joined: 2018-07-11 09:06
Contact:

Re: wait_for_existing_process stops more than one service

Post by Chrispy »

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;
}
Opc Servers: http://www.wowbms.com/index.php/opc-servers
Wow Building & Energy Management System: http://www.wowbms.com/index.php
User avatar
Chrispy
40
40
Posts: 103
Joined: 2018-07-11 09:06
Contact:

Re: wait_for_existing_process stops more than one service

Post by Chrispy »

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);
    }
}
Opc Servers: http://www.wowbms.com/index.php/opc-servers
Wow Building & Energy Management System: http://www.wowbms.com/index.php
User avatar
Rudi De Vos
Admin & Developer
Admin & Developer
Posts: 6863
Joined: 2004-04-23 10:21
Contact:

Re: wait_for_existing_process stops more than one service

Post by Rudi De Vos »

please commit, i will verify it later.
Post Reply