开发者

How to run .reg file in Java

开发者 https://www.devze.com 2022-12-20 09:14 出处:网络
I need to in开发者_如何转开发stall a .reg file (INTRANET) by using Java. How do i get my goal ?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号