How to run .reg file in Java
I need to in开发者_如何转开发stall a .reg file (INTRANET) by using Java. How do i get my goal ?
Cheers,
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.
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.
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.
精彩评论