Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read the Windows Registry from java

 
Miguel Enriquez
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all how Read the Windows Registry from java... basically i need know where are the Favorites folder... i try:

1) readed: http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/Preferences.html
2) System.getProperty("user.home") + "/favorites" but what happend if the windows are in spanish?? a different folder...

i found the exact directory in:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites

but how read the registry???

thanks?
 
Miguel Enriquez
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved!!! i have the version:

C:\programa\java\Mysql>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)

C:\programa\java\Mysql>


//Code
import java.io.*;

public class RegQuery {

private static final String REGQUERY_UTIL = "reg query ";
private static final String REGSTR_TOKEN = "REG_SZ";
private static final String COMPUTER_WINDOWS_FAVORITES_FOLDER = REGQUERY_UTIL +
"\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v Favorites";

public static String getCurrentPCFavorites()
{
try {
Process process = Runtime.getRuntime().exec(COMPUTER_WINDOWS_FAVORITES_FOLDER);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);
if (p == -1)
return null;
return result.substring(p + REGSTR_TOKEN.length()).trim();
}
catch (Exception e) {
return null;
}
}

static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw;

StreamReader(InputStream is) {
this.is = is;
sw = new StringWriter();
}

public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
}
catch (IOException e) { ; }
}

String getResult() {
return sw.toString();
}
}

public static void main(String s[]) {
System.out.println("Personal directory : " + getCurrentUserPersonalFolderPath());
}
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting your solution, that will make it easier for people who have the same question to find the answer with the search function of the forum.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to General Computing.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks now better
 
Mark Spencer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using the above code to get clearcase views -
HKEY_CURRENT_USER\Software\Atria\ClearCase\CurrentVersion\ClearCase Explorer\ViewsPage

but it is returning null.

Whats is the problem I don't know.

I was able to print
HKEY_CURRENT_USER\Software\Atria\ClearCase\CurrentVersion
which is printing correctly.

The code I am using is -


I want to display contents of ViewsPage


Thanks in advance.
 
Maki Jav
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not telling what value you want like


Thanks,

Maki Jav
 
charles jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
related topic in http://www.longhowl.com/howls/139, maybe useful
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drashti Bhuta,
Your post was moved to a new topic.
start topic with new thread
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic