Author
Read the Windows Registry from java
Miguel Enriquez
Ranch Hand
Joined: Mar 13, 2004
Posts: 71
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
Joined: Mar 13, 2004
Posts: 71
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
Bartender
Joined: Aug 16, 2005
Posts: 12907
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.
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Michael Ernest
High Plains Drifter
Sheriff
Joined: Oct 25, 2000
Posts: 7292
Moving to General Computing.
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted Dec 22, 2005 04:44:00
0
looks now better
Mark Spencer
Greenhorn
Joined: Feb 02, 2008
Posts: 8
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
Joined: May 09, 2002
Posts: 423
You are not telling what value you want like
Thanks,
Maki Jav
Help gets you when you need it!
charles jones
Greenhorn
Joined: Apr 25, 2011
Posts: 2
related topic in http://www.longhowl.com/howls/139 , maybe useful
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2547
drashti Bhuta,
Your post was moved to a new topic .
start topic with new thread
SCJP, SCWCD.
|Asking Good Questions |
subject: Read the Windows Registry from java