Search code examples
c#javaprocessversion

Get FileDescription (ProgramName) from .exe


I am developing an activity tracker for my development work in Eclipse (with Java). I now have the program's path and the duration i spent in it.

e.g.: 7min C:\Program Files (x86)\Internet Explorer\iexplore.exe and 10min C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE

I now want to know the name of the program. In C# I get it like this:

System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file);
return (versionInfo.FileDescription == string.Empty) ? null : versionInfo.FileDescription;

Unfortunately, I found no such way in Java and i am not sure if this is even possible?

Thank you!

Edit: I also read this post and the accepted answer but was unable to get the FileDescription...


Solution

  • I am not aware of such API in Java. However, what you can do is as follows:

    1. Create a C# project with the required method that returns program name.
    2. Export this project to DLL.
    3. In your java code you can use JNI to call the native code from you DLL project. You can check these examples: SUN JNI Example , Making Native Windows API calls from within a Java Application

    (I would suggest you to consider whether you absolutely need this description.) Good luck!