1 package org.codehaus.mojo.natives.msvc; 2 3 import org.codehaus.mojo.natives.NativeBuildException; 4 import org.codehaus.plexus.util.cli.CommandLineException; 5 import org.codehaus.plexus.util.cli.CommandLineUtils; 6 import org.codehaus.plexus.util.cli.Commandline; 7 8 public class RegQuery 9 { 10 public static String getValue( String valueType, String folderName, String folderKey ) 11 throws NativeBuildException 12 { 13 Commandline cl = new Commandline(); 14 cl.setExecutable( "reg" ); 15 cl.createArg().setValue( "query" ); 16 cl.createArg().setValue( folderName ); 17 cl.createArg().setValue( "/v" ); 18 cl.createArg().setValue( folderKey ); 19 20 CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); 21 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); 22 23 try 24 { 25 int ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr ); 26 27 if ( ok != 0 ) 28 { 29 return null; 30 } 31 } 32 catch ( CommandLineException e ) 33 { 34 throw new NativeBuildException( e.getMessage(), e ); 35 } 36 37 String result = stdout.getOutput(); 38 39 int p = result.indexOf( valueType ); 40 41 if ( p == -1 ) 42 { 43 return null; 44 } 45 46 return result.substring( p + valueType.length() ).trim(); 47 } 48 }