dcsimg
How to make changes in windows registry?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, August 7, 2002 04:29 AM

Hello! I would like to ask you how can I make changes in the windows registry using java. Right now I am executing the registry file by using exec() method of Runtime class.It is working fine for some pc but for others the problem is that I am getting following error:- Exception in thread "main" java.io.IOException: CreateProcess: start DBReg.reg e rror=2 at java.lang.Win32Process.create(Native Method) at java.lang.Win32Process. (Win32Process.java:66) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:551) at java.lang.Runtime.exec(Runtime.java:418) at    More>>

Hello!


I would like to ask you how can I make changes in the windows registry using java.


Right now I am executing the registry file by using exec() method of Runtime class.It is working fine for some pc but for others the problem is that I am getting following error:-


Exception in thread "main" java.io.IOException:

CreateProcess: start DBReg.reg e
rror=2

at java.lang.Win32Process.create(Native Method)

at java.lang.Win32Process. (Win32Process.java:66)

at java.lang.Runtime.execInternal(Native Method)

at java.lang.Runtime.exec(Runtime.java:551)

at java.lang.Runtime.exec(Runtime.java:418)

at java.lang.Runtime.exec(Runtime.java:361)

at java.lang.Runtime.exec(Runtime.java:325)

at testreg.main(testreg.java:6)


I would like to just know what is the problem with other pcs?Is there any alternate method to make the changes in the windows registry?.

   <<Less

Re: How to make changes in windows registry?

Posted By:   Animesh_Srivastava  
Posted On:   Wednesday, August 7, 2002 06:07 AM

Hi,

I guess you should avoid making a direct call to the reg file using exec("DBreg.reg"), because "executing" reg files on different pcs might have different meanings (though very rarely). Why I say so is because, when you directly call a file this way, then depending upon the extension of the file, an executable program is invoked. For ex, if you type the name of a text file on the cmd prompt then notepad may open if it is the default application for *.txt extension. But this is not guaranteed, because if some other editor (ex Textpad) is set as the default for *.txt then that application will be launched. The correct way therefore, should be to explicitly specify which executable you want to invoke for the given file. Hence I would suggest you explicitly say that regedit.exe should be used for DBreg.reg file. You may like to try out this code and let us know if things are solved to your satisfaction..

public class Proc
{
public static void main (String[] args) throws java.io.IOException, InterruptedException
{
String[] callAndArgs = { "regedit.exe","DBreg.reg"};
Runtime rt = Runtime.getRuntime();
Process child = rt.exec(callAndArgs);
child.waitFor();
System.out.println("Process exit code is: " + child.exitValue());
}
}

Hope that answers your query.

Animesh.
About | Sitemap | Contact