2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // From: http://www.rgagnon.com/javadetails/java-0652.html
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 // Contact: phylosoft @ gmail . com
22 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24 package org.forester.util;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.StringWriter;
30 public class WindowsUtils {
32 private static final String REGQUERY_UTIL = "reg query ";
33 private static final String REGSTR_TOKEN = "REG_SZ";
34 private static final String DESKTOP_FOLDER_CMD = REGQUERY_UTIL
35 + "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\"
36 + "Explorer\\Shell Folders\" /v DESKTOP";
38 private WindowsUtils() {
41 public static String getCurrentUserDesktopPath() {
43 final Process process = Runtime.getRuntime().exec( DESKTOP_FOLDER_CMD );
44 final StreamReader reader = new StreamReader( process.getInputStream() );
48 final String result = reader.getResult();
49 final int p = result.indexOf( REGSTR_TOKEN );
53 return result.substring( p + REGSTR_TOKEN.length() ).trim();
55 catch ( final Exception e ) {
60 static class StreamReader extends Thread {
62 private final InputStream is;
63 private final StringWriter sw;
65 StreamReader( final InputStream is ) {
67 sw = new StringWriter();
78 while ( ( c = is.read() ) != -1 ) {
82 catch ( final IOException e ) {