4

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...

Community
  • 1
  • 1
casaout
  • 1,819
  • 3
  • 24
  • 54
  • I found a very good hint here at StackOverflow: http://stackoverflow.com/questions/8052862/how-to-get-the-file-description-of-a-dll-or-exe?lq=1 With that I was able to get the file version. Unfortunately I was unable to adapt it to my needs to ghet the FileDescriptions. – casaout Sep 10 '12 at 08:32

2 Answers2

1

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!

aviad
  • 8,229
  • 9
  • 50
  • 98
  • Thanks @aviad for your post. I will try this way if the way I just found out (but have a little problem see above) will not work. Unfortunately I found no other possibility of showing the user the program name instead of this description... – casaout Sep 10 '12 at 08:43
  • 1
    Just a shot in the dark: build your own dictionary that maps from iexplore.exe->Internet explorer etc. look up for as many executables as you can and I believe that you will get to 90% coverage very soon – aviad Sep 10 '12 at 09:42
  • that was a thought of mine too... Thanks. – casaout Sep 10 '12 at 11:26
0

It took me forever to find this, but I finally was able to piece together this inline script: (get-command *.exe).fileversioninfo.filedescription Now I used *.exe and .filedescription because I was attempting to return the prettified file names for every exe in a directory, but you can use any of the available variables.