5

I need to install a .reg file (INTRANET) by using Java. How do i get my goal ?

Cheers,

3 Answers 3

6

You could use System.exec to launch regedit yourfile.reg

Here is how to do it :

String[] cmd = {"regedit", "yourfile.reg"};
Process p = Runtime.exec(cmd);
p.waitFor();

Last line is optional, it only allows you to wait until the operation is over.

Sign up to request clarification or add additional context in comments.

1 Comment

is that requiring the administrator priviledges @ValentinRocher ?
6

If you're already on Java 1.6, just grab java.awt.Desktop:

Desktop.getDesktop().open(new File("c:/yourfile.reg"));

It will launch the file using the default application associated with it, as if you're doubleclicking the particular file in Windows explorer.

Comments

1

This can achieved through Process Builder in JAVA. Please consider the following example for this:

ProcessBuilder processBuilder = new ProcessBuilder("regedit", "reg_file_to_run.reg");
Process processToExecute = processBuilder.start();

And then you can optionally wait for the completion of process execution with this line:

processToExecute.waitFor();

Note: If command in your registry file asks for confirmation prompts while making changes in registry entries, you can perform it silently as well with '/s' option. Like this:

ProcessBuilder processBuilder = new ProcessBuilder("regedit", "/s", "reg_file_to_run.reg");

With this command would be executed silently without any confirmation prompt.

1 Comment

is this calling require us to be administrator mode first in windows envrionment?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.