Blocking Mouse Hook for a vb.net application when the task manager has focus.

jacky Perpète 126 Reputation points
2025-04-18T09:07:49.86+00:00

Hello,

For a VB.NET application with WPF, I'm using a transparent window that follows the movement of the mouse cursor on the screen.

This application uses the mouse hook to handle the move event.

This window represents a custom cursor.

This test application works correctly except on Windows applications like Task Manager or Device Manager.

When one of these windows gains focus, the mouse hook is disabled in my application.

How can I prevent this?

I've seen custom cursors using the same principle that don't have this problem.

I'm attaching my test program in VB under WPF.To attach it.

I changed the file extension from .zip to .txt.

To use it, you'll need to change the extension from .txt to .zip.

WpfCursorWindow.txt

TestHookMouse

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,827 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 48,151 Reputation points
    2025-04-18T14:13:56.1133333+00:00

    If you are signed-on as an account that is a member of the Administrators group then Task Manager will auto-elevate so it will run with a high integrity level. Your application runs at medium integrity so Windows built-in security measures prevent the low-level mouse hook from interacting with Task Manager.

    You can work around this by making your application a UIAccess application. This is done by signing the application, installing it to a protected file system location and manifesting it with uiAccess=true. An alternative is to run the application with elevated privileges as Administrator though this is probably not what you would want. The screen capture isn't very good but it does demonstrate the solution works -

    UIAccess

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.