Results 1 to 6 of 6
  1. #1
    PrinceSendai is offline Member
    Join Date
    Jul 2010
    Location
    Lima, Peru
    Posts
    47
    Rep Power
    0

    Angry Editing Registry Fails

    This is my program (Im using Windows 7)

    Java Code:
    public class Example{
    
    
    	public static String command = "REG ADD HKLM\\... /v Name /t REG_DWORD /d Value";      //Replace ... with a valid path, Name with a valid key, and Value with a number
    
    
    	public static void main(String[] args){
    		try{
    
    
    			Runtime.getRuntime().exec(command)
    			
    		}
    		catch(Exception e){
    			e.printStackTrace(System.err);
    			
    		}
    		
    
    	}
    
    
    
    }

    The problem I am having is that the registry key is not being edited, as it should.

    I tried using a REG QUERY command and it works fine. My program is able to read the registry just fine. However, when I try to write to the registry (as above), my program runs without errors but when I check the registry, the registry key hasn't been edited at all.

    I previously thought that it had something to do with Admin rights. However, I logged in as an Administrator and my program still didn't work correctly.

    Also, I tested the "command" variable by typing it directly into the console, and the command works fine! In other words, I have no idea why Java is plugging in the correct command but the changes are being made.


    Now, I have small suspicion. When I type in the command in the console, the console ASKS ME IF I WANT TO REPLACE THE EXISTING REGISTRY ENTRY, to which I respond with a "y".

    Maybe this little step is causing the issue? Is my program prompting the user for a "y" in the background, without me noticing? If that is the case, how do I get access to this prompt, and more specifically, how do I make my program feed a "y" into this? This is all really abstract for me and I'm lost.

    Please help!
    Last edited by PrinceSendai; 05-31-2011 at 10:00 PM. Reason: clear up code

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Try the simplest solution first. Is there an option for the REG command that makes it non-interactive?
    Get in the habit of using standard Java naming conventions!

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Perhaps there are error messages that you haven't coded for.
    Get the Process returned from exec, get the Streams from that process and print them.

    how do I make my program feed a "y" into this?
    You can use a Stream to the Process to feed the program.

  4. #4
    PrinceSendai is offline Member
    Join Date
    Jul 2010
    Location
    Lima, Peru
    Posts
    47
    Rep Power
    0

    Default

    kjkrum

    Try the simplest solution first. Is there an option for the REG command that makes it non-interactive?

    I tried this and it worked! Had not thought about it, thanks!


    Thanks guys

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    You got away with an easy fix this time, but you need to go through all the sections of When Runtime.exec() won't - JavaWorld

    db

  6. #6
    PrinceSendai is offline Member
    Join Date
    Jul 2010
    Location
    Lima, Peru
    Posts
    47
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    You got away with an easy fix this time, but you need to go through all the sections of When Runtime.exec() won't - JavaWorld

    db
    Thank you for the useful guide.

Similar Threads

  1. check registry key
    By anilkumar_vist in forum Advanced Java
    Replies: 5
    Last Post: 11-22-2009, 04:52 PM
  2. Access registry
    By kkk in forum Advanced Java
    Replies: 8
    Last Post: 09-01-2009, 12:16 PM
  3. RMI registry
    By tarunkumar in forum Advanced Java
    Replies: 1
    Last Post: 09-30-2008, 08:02 PM
  4. Registry Problem
    By Mir in forum New To Java
    Replies: 1
    Last Post: 07-19-2008, 04:12 PM
  5. windows registry
    By Fleur in forum New To Java
    Replies: 3
    Last Post: 06-20-2008, 03:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •