Results 1 to 6 of 6
Thread: Editing Registry Fails
- 05-31-2011, 09:55 PM #1
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
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
- 05-31-2011, 11:36 PM #2
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!
- 06-01-2011, 12:01 AM #3
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.
You can use a Stream to the Process to feed the program.how do I make my program feed a "y" into this?
- 06-01-2011, 10:04 PM #4
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
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
- 06-02-2011, 09:04 AM #5
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
- 06-20-2011, 05:33 PM #6
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
Similar Threads
-
check registry key
By anilkumar_vist in forum Advanced JavaReplies: 5Last Post: 11-22-2009, 04:52 PM -
Access registry
By kkk in forum Advanced JavaReplies: 8Last Post: 09-01-2009, 12:16 PM -
RMI registry
By tarunkumar in forum Advanced JavaReplies: 1Last Post: 09-30-2008, 08:02 PM -
Registry Problem
By Mir in forum New To JavaReplies: 1Last Post: 07-19-2008, 04:12 PM -
windows registry
By Fleur in forum New To JavaReplies: 3Last Post: 06-20-2008, 03:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks