IMessageFilter not working under administrative privileges

201 Views Asked by At

I am using an IMessageFilter for tracking the user input by mouse and keyboard.

static void Main()
{
    try
    {
         AddKeyboardMouseDevice(this.Handle);
         RegisterDevices();
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unhandled exception occurred tray application." + ex.Message);
    }
}

public void AddKeyboardMouseDevice(IntPtr windowHandle)
{
    devices.Add(new RAWINPUTDEVICE(1, 6, 0x100, windowHandle));
    devices.Add(new RAWINPUTDEVICE(1, 2, 0x100, windowHandle));
}

public bool RegisterDevices()
{
    if (devices.Count == 0) return false;
    log.DebugFormat("Registering for keyboard mouse hook");
    RAWINPUTDEVICE[] d = devices.ToArray();
    bool result = RegisterRawInputDevices(d, devices.Count, Marshal.SizeOf(typeof(RAWINPUTDEVICE)));
    return result;
}

public bool PreFilterMessage(ref Message m)
{
    if (m.Msg == WM_INPUT)
    {
        int pcbSize = Marshal.SizeOf(typeof(RawInput));

        RawInput pData = new RawInput();
        int result = GetRawInputData(m.LParam,
            RawInputCommand.Input, out pData,
            ref pcbSize, Marshal.SizeOf(typeof(RAWINPUTHEADER)));
        if (result != -1)
        {
            ProcessRawInput(pData, m.LParam);
        }
    }
    return false; 
}

But my problem is, when a process runs under administrative privileges, then i don't get any messages. How can I get these messages for a process running under administrative privileges?

0

There are 0 best solutions below