How to run a .reg file in Java

I need to install a REG file (INTRANET) using Java. How to get your goal?

Greetings

+5
source share
3 answers

You can use System.exec to runregedit yourfile.reg

Here's how to do it:

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

The last line is optional, it only allows you to wait for the operation to complete.

+6
source

If you are already on Java 1.6, just take 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 had double-clicked a specific file in Windows Explorer.

+6
source

Process Builder JAVA. :

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

:

processToExecute.waitFor();

Note. If a command in the registry file asks for confirmation when making changes to the registry entries, you can also execute it using the "/ s" option. Like this:

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

This command will be executed without any confirmation prompts.

0
source

All Articles