1

I am using the below code to get the pointer location but windows 10 blocks the access as I run the application.

 while (true) {
        //Thread.sleep(100);
        try {
            System.out.println("(" + MouseInfo.getPointerInfo().getLocation().x
                    + ", "
                    + MouseInfo.getPointerInfo().getLocation().y + ")");
        } catch (Exception e) {
            e.printStackTrace();
        }

Error:
A notification pops up in the notification panel saying:

Unauthorized Changes blocked Controlled folder access blocked netbeans64.exe from making changes.

Notification Details
enter image description here

It was working fine before accessing the pointer location. There's no exception thrown by e.printstacktrace(). What am I supposed to do?

Update
If I allow it from the Defender settings, I'm able to access the pointer location. How can I enable it from Java? it will lead every person using the app to allow it from Defender Settings which doesn't seem quiet right. Any Ideas please?

Jamshaid
  • 370
  • 2
  • 11
  • 40
  • 1
    The message says that Netbeans64.exe, in other words your IDE, is trying to access `%userprofile%/Documents/NetBeansProject\…\src\…`, in other words, your source code folder. This looks like a normal, legitimate action and entirely unrelated to the fact that your program accesses the pointer location, as a) your program wouldn’t have the name “Netbeans64.exe” and b) your compiled program doesn’t access the source code folder. When you say, your previous version worked, it probably boils down to Defender just preventing changing or recompiling the source code. – Holger Mar 11 '20 at 08:02

1 Answers1

0

I had this problem once. It turned out that some folders on Windows are treated as special folders, that when somehow modified by an app, raise this alert. user's Documents folder is one of those folders(so are probably Pictures, Downloads and C:\Windows etc.). From your screenshot we see that your app project runs in %userprofile%/Documents/NetBeansProject... directory. If you run the app through some build system/IDE, it probably creates some temporary files. This is captured by Defender and blocked.

Simply try... moving the project out of the Documents folder. (it worked for me when I had this problem).

If it doesn't work, then it might be something correlated to the java SecurityManager and the case that MouseInfo could somehow trigger SecurityException or some other mechanism as they write in the documentation

Anyway, give info if this helps.

Tooster
  • 322
  • 3
  • 14
  • 1
    The first part is going into the right direction. The `SecurityManager` is irrelevant, as the OP already stated that there are no exceptions. – Holger Mar 11 '20 at 08:04