Changing the process name of Java program in windows

You have invoked several Java programs simultaneously. However, one of the programs is misbehaving and you decide to kill it. Well, you think It is a straightforward task - Just open Windows Task Manager, right click on the misbehaved program and click End Task in the context menu.

However, you find it is not as simple as you thought - When you open the Windows Task Manager you see several java.exe processes and you do not have a clue which one is the misbehaved Java program you want to kill. Let's see how we can solve this problem and overcome this issue

Windows Task Manager and image name

Windows Task Manager displays the image name of the process - In other words Windows Task Manager shows the binary file which was loaded to memory and was executed by windows operating system.

Using this observation, we can overcome the issue by coping java.exe to a unique name and invoke instead of java.exe. Why ?

First, Since this new file is a copy java.exe, we can invoke it, as usual, to execute any Java program.

Second, When the file is invoked you will the newly copied file name and will not see java.exe in Windows Task Manager anymore.

The script

To automate this solution, we can write a simple batch file. Create a new file named java-by-name.bat in the java directory with the following contents:

 set JAVA_OLD="%JAVA_HOME%java.exe"
 set JAVA_NEW="%JAVA_HOME%%1.exe"       

 copy "%JAVA_OLD%" "%JAVA_NEW%"
 set args=%*
 set args=%args:* =%
 "%JAVA_NEW%" %args%


Now, Let's see how we can use this above batch to distinguish between your java programs

Suppose you want to run the following command:

Invoke the following command instead:
 java_by_name unique_java
Now, unique_java.exe process will appear in Windows Task Manager instead of java.exe.