получить PID модификатора, когда реестр изменен с помощью winapi - PullRequest
0 голосов
/ 08 ноября 2019

Я пытаюсь получить информацию о процессе (включая PID, имя, путь и т. Д.), Который пытается изменить реестр Windows. для этого я написал программу для win32, в которой CreateEvent() вызывается для обработчика событий и RegNotifyChangeKeyValue() вызывается для уведомления

Так что при любом изменении этого (заданного) пути в реестре я получаю уведомление (элемент управления)в моей программе Но проблема в том, что если мне нужна информация о том, кто вносит изменения в реестр (идентификатор процесса / имя) и какое значение изменил процесс, я не могу получить с помощью вызовов winapi

canкто-нибудь поможет мне от этого?

below, is my recent win32 c code, please have a look on it

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

// Globals variable
static HKEY   hKey;
static HANDLE hEvent;
static LONG   lErrorCode;


//
// Handler
//
BOOL WINAPI consoleHandler(DWORD signal) {

    if (signal == CTRL_C_EVENT)
    {
        printf("Ctrl-C handled\n"); // do cleanup

        //====================================================================
        // Close the key.
        //
        //====================================================================
        lErrorCode = RegCloseKey(hKey);
        if (lErrorCode != ERROR_SUCCESS)
        {
            printf("Error in RegCloseKey (%d).\n", GetLastError());
            return FALSE;
        }

        //====================================================================
        // Close the handle.
        //
        //====================================================================
        if (!CloseHandle(hEvent))
        {
            printf("Error in CloseHandle.\n");
            return FALSE;
        }

    }

    ExitProcess(0);
    return TRUE;
}

//void main(int argc, char *argv[])
void __cdecl _tmain(int argc, TCHAR* argv[])
{
    DWORD  dwFilter = REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY;


    HKEY   hMainKey;

    //====================================================================
    // Create Key
    //
    //====================================================================

    // String KEY
    // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Demo

    hMainKey = HKEY_LOCAL_MACHINE;
    char subkey[100] = "SYSTEM";

    //=====================================================================
    // Open a key.
    //
    //=====================================================================
    lErrorCode = RegOpenKeyEx(hMainKey, subkey, 0, KEY_NOTIFY, &hKey);
    if (lErrorCode != ERROR_SUCCESS)
    {
        printf("Error in RegOpenKeyEx (%d).\n", lErrorCode);
        return;
    }

    //====================================================================
    // Create an event.
    //
    //====================================================================
    hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (hEvent == NULL)
    {
        printf("Error in CreateEvent (%d).\n", GetLastError());
        return;
    }



    //====================================================================
    // set handler ctrl+c
    //
    //====================================================================

    if (!SetConsoleCtrlHandler(consoleHandler, TRUE))
    {
        printf("\nERROR: Could not set control handler");
    }
    else
    {
        // Monitor continuously
        while (TRUE)
        {

            //=====================================================================
            // Notify - Register Event
            // Watch the registry key for a change of value.
            //
            //=====================================================================
            lErrorCode = RegNotifyChangeKeyValue(hKey, TRUE, dwFilter, hEvent, TRUE);
            if (lErrorCode != ERROR_SUCCESS)
            {
                printf("Error in RegNotifyChangeKeyValue (%d).\n", lErrorCode);
                return;
            }

            // Get the message
            printf(TEXT("Waiting for a change in the specified key...\nPress (CTRL + C) to terminate\n"));
            if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
            {
                printf("Error in WaitForSingleObject (%d).\n", GetLastError());
                return;
            }
            else
            {
                printf("\n[HERE] : Change has occurred.\n\n");
            }
        }
    }

    //====================================================================
    // Close the key.
    //
    //====================================================================
    lErrorCode = RegCloseKey(hKey);
    if (lErrorCode != ERROR_SUCCESS)
    {
        printf("Error in RegCloseKey (%d).\n", GetLastError());
        return;
    }

    //====================================================================
    // Close the handle.
    //
    //====================================================================
    if (!CloseHandle(hEvent))
    {
        printf("Error in CloseHandle.\n");
        return;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...