How to Resolve JConsole "the management agent is not enabled on this process"

On the other day, I ran into a weird situation. I opened the JConsole as usual, to my surprise, I found all local process grey out except for the Jconsole itself as below:

and when I click on one process, it would show "The Management agent is not enabled on this process" as below:

The weird thing is, it worked OK before, and I had not done anything to it!

The first "Solution" I googled out is :
1.Create a temp folder “C:\Tmp”
2.Change Windows default temp folder to your folder in System Environment variables.
3.Restart your Java Application and JConsole.

Unfortunately, it didn't work.

The second try is add "-Dcom.sun.management.jmxremote" as VM parameter when you run the java application, still no luck, though.

After long time google search without a real solution, I almost gave up. Suddenly, an idea crossed my mind, how about checking other java build-in tools? So I open the Java installation bin directory, and click on every file with *.exe extension. All is good until I open the jvisualvm.exe, it turned out to be:

What a similar symptom! I got a feeling that I was close to the truth! Then I followed to the link as the error message said to found this explanation and workaround:

Local Applications Cannot Be Monitored (Error Dialog On Startup)

Description: An error dialog saying that local applications cannot be monitored is shown immediately after VisualVM startup. Locally running Java applications are displayed as (pid ###).
Resolution: This can happen on Windows systems if the username contains capitalized letters. In this case, username is UserName but the jvmstat directory created by JDK is %TMP%\hsperfdatausername. To workaround the problem, exit all Java applications, delete the %TMP%\hsperfdatausername directory and create new %TMP%\hsperfdata_UserName directory.

And I made the changes as it said and guess what? It worked! And added bonus is, JConsole worked normally as well!

Although I have fixed that problem, I don't know the defacto root cause to it. I guess it is because both JConsole and JVisualVM need that foler to store runtime data, but some other programs happened to modify that folder's name to lower case username. But I don't know which program I have ran/installed.

Written on 07 April 2016