473,503 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write to windows registry

35 New Member
hai,
I am tryng to write installation for an application,which require to set some values in registry using java program.

I have tried using Preference class in java.util.prefs

This allows to write keys and values under the keys

HKEY_LOCAL_MACHINE/software/JavaSoft/Prefs
or
HKEY_CURRENT_USER/software/JavaSoft/Prefs


But i want to write under

HKEY_LOCAL_MACHINE/software/ mycompanyName

Please anyone help me its urgent Is there any api it will be helpful if i get some code samples also.
thank you
prakash
Feb 7 '07 #1
5 19510
sicarie
4,677 Recognized Expert Moderator Specialist
123456prakash-

I found this link to Sun's site after a quick Google-search of "java write windows registry".

http://forum.java.sun.com/thread.jsp...sageID=3902531

If that doesn't work, it looks like a few others in that search might.

sicarie
Feb 7 '07 #2
rengaraj
168 New Member
you can use Package java.util.prefs
here is some code
--

Expand|Select|Wrap|Line Numbers
  1. package com.kanad.reg;
  2. import java.util.prefs.*;
  3.  
  4. public class winReg {
  5. Preferences prefs;
  6. String defaultValue = "NA";
  7. String InstalledDate ="",version="";
  8.     public static void main(String[] args)
  9.         {
  10.          com.kanad.reg.winReg wr=new com.kanad.reg.winReg();
  11.          wr.setValue();
  12.          wr.getValue();
  13.         }
  14.     winReg()
  15.     {
  16.         try
  17.         {  
  18.            //HKEY_CURRENT_USER\Software\JavaSoft\Prefs
  19.            //HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
  20.            prefs= Preferences.userNodeForPackage(com.kanad.reg.winReg.class);//HKEY_CURRENT_USER
  21. //           prefs= Preferences.systemNodeForPackage(com.kanad.reg.winReg.class);//HKEY_LOCAL_MACHINE
  22.         }
  23.         catch (Exception E)
  24.         {
  25.             System.out.println(E);
  26.         }
  27.  
  28.     }//winReg
  29.     public void setValue()
  30.     {
  31.         try
  32.         {
  33.         prefs.put("Installed",new java.util.Date().toString());
  34.         prefs.put("Version","1.0.0");
  35.         }
  36.         catch (Exception E)
  37.         {
  38.             System.out.println(E);
  39.         }
  40.     }
  41.     public void getValue()
  42.     {
  43.          try
  44.          {
  45.                InstalledDate = prefs.get("Installed", defaultValue);
  46.                version= prefs.get("Version", defaultValue);
  47.                System.out.println("Installed "+InstalledDate+"\nVersion "+version);
  48.                prefs.flush();
  49.          }
  50.          catch (Exception E)
  51.          {
  52.              System.out.println(E);
  53.          }
  54.     }
  55. }
In registry search for Prefs
you will have com/kanad/reg key
I don't know whether this code works for linux
Feb 17 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
you can use Package java.util.prefs
here is some code
--

Expand|Select|Wrap|Line Numbers
  1. package com.kanad.reg;
  2. import java.util.prefs.*;
  3.  
  4. public class winReg {
  5. Preferences prefs;
  6. String defaultValue = "NA";
  7. String InstalledDate ="",version="";
  8.     public static void main(String[] args)
  9.         {
  10.          com.kanad.reg.winReg wr=new com.kanad.reg.winReg();
  11.          wr.setValue();
  12.          wr.getValue();
  13.         }
  14.     winReg()
  15.     {
  16.         try
  17.         {  
  18.            //HKEY_CURRENT_USER\Software\JavaSoft\Prefs
  19.            //HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
  20.            prefs= Preferences.userNodeForPackage(com.kanad.reg.winReg.class);//HKEY_CURRENT_USER
  21. //           prefs= Preferences.systemNodeForPackage(com.kanad.reg.winReg.class);//HKEY_LOCAL_MACHINE
  22.         }
  23.         catch (Exception E)
  24.         {
  25.             System.out.println(E);
  26.         }
  27.  
  28.     }//winReg
  29.     public void setValue()
  30.     {
  31.         try
  32.         {
  33.         prefs.put("Installed",new java.util.Date().toString());
  34.         prefs.put("Version","1.0.0");
  35.         }
  36.         catch (Exception E)
  37.         {
  38.             System.out.println(E);
  39.         }
  40.     }
  41.     public void getValue()
  42.     {
  43.          try
  44.          {
  45.                InstalledDate = prefs.get("Installed", defaultValue);
  46.                version= prefs.get("Version", defaultValue);
  47.                System.out.println("Installed "+InstalledDate+"\nVersion "+version);
  48.                prefs.flush();
  49.          }
  50.          catch (Exception E)
  51.          {
  52.              System.out.println(E);
  53.          }
  54.     }
  55. }
In registry search for Prefs
you will have com/kanad/reg key
I don't know whether this code works for linux
Probably not, as Linux doesn't have a registry. (Unless a program such as Symantec specifically creates it).
Feb 19 '07 #4
jetblackstar
1 New Member
Actually i believe Linux is covered. Wonders of the Abstract Java concept.
For the UserRoot for package it stores them in a hidden .java folder using the package as a series of directories in the users home directory.
For System i believe it stores it in /etc but not 100% sure of the latter.

I was pleasantly surprised when one of our apps just "worked" on Linux.
The only thing that didn't was running up .csv files in the default because it executed "cmd"

Preferences class allows access to HK_CURRENT_USER and HK_LOCAL_MACHINE but does anyone know how you can access the other registry roots under windows. i.e. HKEY_CLASS_ROOT for example, i need to alter default file associates.
Many thanks
Jul 31 '08 #5
JosAH
11,448 Recognized Expert MVP
Preferences class allows access to HK_CURRENT_USER and HK_LOCAL_MACHINE but does anyone know how you can access the other registry roots under windows. i.e. HKEY_CLASS_ROOT for example, i need to alter default file associates.
Many thanks
You can't; the Preferences classes define their own two roots as you might have
noticed. There is no way to get 'above' those. Those Preferences are not a general
MS Windows registry manipulation package.

kind regards,

Jos
Jul 31 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1962
by: Pat Blair | last post by:
Sorry to anyone who read this post, but in case it's useful to anyone: Further experiments reveal that while a tuple comes back if you read a multi-line string, you set the value using a list (not...
3
3703
by: Danny | last post by:
Hi I just have a quick question. One of our Windows based application uses the registry for configuration type options and some other things. I want to modify our application to move to use a...
1
1947
by: Gerard Marshall Vignes | last post by:
I was recently cautioned against storing an ADO.NET Connection String in the Windows Registry because access to the Windows Registry would be serialized and therefore impact scalability. I have...
1
1567
by: Nikolay Petrov | last post by:
I cannot write to windows registry using ASP .NET account. I have made a key in HKEY_LOCAL_MACHINE\Software and granted full access to ASP .NET account, but still got "Requested registry access is...
3
5723
by: Nikolay Petrov | last post by:
Why I always get 'Requested registry access is not allowed' when i try to Read/Write to Windows Registry from ASP service. I use ASP NET account? Also granted full permissions to required Registry...
3
2347
by: Mark Findlay | last post by:
When programming reads of the Windows Registry, do the registry keys and values need to be localized for international use? For example, do I need to convert the key name...
4
6338
by: korund | last post by:
Is there any difference to read & write to windows Registry with VBScript or JavaScript? Both scripting languages have similar syntax. What is preferable use for this? thanks.
11
19906
by: gloriajstitcher | last post by:
I have an embroidery software program on my computer. When I go to options to enable the iconizer settings (seeing my design files as pictures), a box comes up that says "Can't write to Windows...
1
2694
by: kbnumesh | last post by:
Dear All, I have query regarding the registry. Is it possible to write it to windows registry using the XML? if yes then what is the API or tag used to write it. I am just a beginner in...
1
1511
by: somersbd | last post by:
I have a simple text file that I need to read and then write each line to the same key in the registry. Example: Text file name version.txt with the following lines HP 01/01/2008 4 and would...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.