[clamav-win32] Re: w32.clamav.net

clamav-win32 at subscriptions.pizzolato.net clamav-win32 at subscriptions.pizzolato.net
Thu Sep 21 14:08:24 CEST 2006


On Thursday, September 21, 2006 at 12:49 AM, Nigel Horne wrote:
> Mark Pizzolato wrote:
>
> > When the ClamAV service is stopping, you might want to try cleanly
> > stopping freshclam with:
> >
> >         GenerateConsoleCtrlEvent(CTRL_C_EVENT, dwProcessId);
> >
> > Where dwProcessId is the process ID of the freshclam process saved
when
> > the process was created.
> 
> That code has been in there for some time, but it fails - it generates
> error 6 - incorrect handle. I am aware of the issue.

Sorry, I didn't know that.  The only help I can offer then, is to
describe what code I have written elsewhere, which runs in the context
of a service does.  The following is used to start the executable:

    PROCESS_INFORMATION pinfo;
    DWORD status = ERROR_SUCCESS;

    szCommandLine = (TCHAR *)malloc(sizeof(*szProgram)* 
                (4+((szProgram)? _tcslen(szProgram) : 0) + 
                   ((szProgramArguments)? _tcslen(szProgramArguments) :
0)));
    if (szProgram)
        {
        if (szProgramArguments)
            _stprintf(szCommandLine, "\"%s\" %s", szProgram,
szProgramArguments);
        else
            _stprintf(szCommandLine, "\"%s\"", szProgram);
        }
    else
        if (szProgramArguments)
            _tcscpy(szCommandLine, szProgramArguments);
        else
            *szCommandLine = NULCHAR;
    if (!CreateProcess(szProgram, 
                       szCommandLine, 
                       NULL, 
                       NULL, 
                       TRUE,
                       CREATE_NEW_PROCESS_GROUP |
                       NORMAL_PRIORITY_CLASS,
                       NULL, 
                       szWorkingDirectory, 
                       NULL, 
                       &pinfo))
        status = GetLastError();
    free(szCommandLine);
    if (status  == ERROR_SUCCESS)
        {
        CloseHandle(pinfo.hProcess);
        CloseHandle(pinfo.hThread);
        }

On success, the returned pinfo structure contains the dwProcessId which
is later used at shutdown time to pass to GenerateConsoleCtrlEvent().

- Mark Pizzolato




More information about the clamav-win32 mailing list