• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

list all software + version on computer

it is possible to achieve this using java?

can java access reg keys like:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*\DisplayName
0
ellandrd
Asked:
ellandrd
  • 16
  • 8
  • 7
  • +2
3 Solutions
 
kawasCommented:
you can get a registry key by executing
Runtime.getRuntime().exec("cmd /c reg query <registry_key>");
and parsing the output.
0
 
CEHJCommented:
Some keys you can read. Others not. To read any, you need JNI. See

http://www.codeproject.com/useritems/JNI.asp
0
 
StillUnAwareCommented:
Unless You use some special library like this:

http://www.bayequities.com/tech/Products/jreg_key.shtml
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
StillUnAwareCommented:
I'd recommend the kawas suggestion, it's the simplest way and You will always be able to control it the way You want it.
0
 
ellandrdAuthor Commented:
well basically im wanting to list any software and its version that is installed on the machine that is viewing our intranet...

server supports JAVA, ASP, PHP, ASP.NET...

0
 
ellandrdAuthor Commented:
dont fully understand kawas solution.. i cant see in my head how it works... i need to understand its output... and how it would look before i write some code...
0
 
ellandrdAuthor Commented:
would this *special library* have to be installed on each client workstation?  if yes - forget it...
0
 
kawasCommented:
input into a dos prompt
    reg query HKEY_LOCAL_MACHINE\SOFTWARE

you will get the idea from that
0
 
ellandrdAuthor Commented:
how could i parse the output of:

Runtime.getRuntime().exec("cmd /c reg query <registry_key>");
0
 
kawasCommented:
Process p;
            try {
                  p = Runtime.getRuntime().exec("cmd /c reg query <registry_key>");
                  BufferedReader br = new BufferedReader(new InputStreamReader(p
                              .getInputStream()));
                  String line = "";
                  while ((line = br.readLine()) != null) {
                                 // line is each line of output
                  }
                  p.waitFor();
                catch (Exception e) {
                 }
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW, this is an OS specific question, isn't it? The same solution will not work on Unix.
0
 
kawasCommented:
is there a windows registry on unix?
0
 
ellandrdAuthor Commented:
guys, we work with IE, windows xp pro  - *nix doesnt come into the senerio...
0
 
kawasCommented:
if you are talking about the process part, it can be done similarly on unix (replace "cmd /c reg query <registry_key>", with something like "ls")
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> is there a windows registry on unix?

No, I was wondering what other method to follow in case the same program has to run on any other OS.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> if you are talking about the process part, it can be done similarly on unix

Yes, if there is a command like that, it will be easy by keeping the command-name in a properties-file. However, the command response will be in different formats and will have to be handled accordingly.
0
 
ellandrdAuthor Commented:
OK i can list the programs that i want, but how do i get their version?
0
 
ellandrdAuthor Commented:
also see for example, i have this:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe\\Acrobat Reader

i have noticed keys with spaces done display... any ideas?
0
 
kawasCommented:
reg query HKEY_LOCAL_MACHINE\SOFTWARE
returns a list keys, for instance HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB"
returns another list, i.e.
   ! REG.EXE VERSION 3.0

   HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB

   HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Server 5.0

req query "HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Server 5.0"
returns what you want:
   Location    REG_SZ  C:\Program Files\MySQL\MySQL Server 5.0\
   Version     REG_SZ  5.0.16

You will have to recurse on the output until you get what you want.
0
 
ellandrdAuthor Commented:
also how can i just read the top level of directory?

example: HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe and nothing underneath it... sorry nothing inside that folder...
0
 
kawasCommented:
keys with spaces need to be wrapped in quotes
0
 
ellandrdAuthor Commented:
wrapped in quotes?

Runtime.getRuntime().exec("cmd /c reg query 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe\\Adobe Reader'")

still dont show anything...
0
 
kawasCommented:
Runtime.getRuntime().exec("cmd /c reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe\\Adobe Reader\"");
0
 
ellandrdAuthor Commented:
also how can i just read the top level of directory?

example: HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe and nothing underneath it... sorry nothing inside that folder...
0
 
CEHJCommented:
:-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Keep it all in a properties-file like I said so you don't have to worry about escaping for multiple \\, etc
0
 
ellandrdAuthor Commented:
how can i just read the top level of directory?

example: HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe and nothing underneath it... sorry nothing inside that folder..
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Not sure - it will require some native Windows command, I guess. Better ask in that TA ;-)
0
 
ellandrdAuthor Commented:
is there a windows programming TA?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes under Programming -> Platforms, there is a Win Prog TA. You can also ask in Programming or in C++ I guess.
0
 
StillUnAwareCommented:
This works like a charm:

    BufferedReader br = new BufferedReader(new InputStreamReader(
        Runtime.getRuntime().exec("cmd /c reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe\"").getInputStream()));
    String line = null;
    while((line = br.readLine()) != null)
      System.out.println(line);

For example on my PC  I've got these results:

"
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe Bridge
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe Gamma
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe Help Center
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe Stock Photos
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\CommonFiles
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\DefaultLanguage
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\DLM
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\ExtendScript Toolkit
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Linguistics
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Media Browser
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\PDF Settings
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Photoshop
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\SubInstall"

Notice the first empty line, but all this can be filterred. If You don't want to see the empty lines and the directory tree elements, then do this:

    String path = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Adobe";
    BufferedReader br = new BufferedReader(new InputStreamReader(
        Runtime.getRuntime().exec("cmd /c reg query \""+path+"\"").getInputStream()));
    String line = null;
    while((line = br.readLine()) != null)
      if((line.length() > 0) && !line.startsWith(path))
        System.out.println(line);

the output is empty, cause that directory has no data other than directories. To see the sample code working try running the command from command line:

  reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"

and try setting the String 'path' equal to "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion".

I guess this is what You are looking for, and if not, can You be more precise.
0
 
ellandrdAuthor Commented:
will yes - its kinda what im after!  

my goal is basically access the registry using an signed applet and get a list of all the installed software and send it a webpage.

but for *example*, the adobe directory, i would only want the top level like:

"HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Adobe" and nothing under that level...

do this for all software so i get a nice list that i can output to a webpage...

can you help?  i will open another thread if you can help me acheive this?
0
 
StillUnAwareCommented:
Yes, I think I can suggest You a few tips on that question.
0
 
ellandrdAuthor Commented:
tips or help code a *working solution* ?
0
 
StillUnAwareCommented:
I'm working on it :)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Might be better to ask in a new question so that everybody can see.
0
 
ellandrdAuthor Commented:
yes i am, but im not opening a new question for *tips* - im looking to code a working solution

question coming in 2 mins
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 16
  • 8
  • 7
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now