Hi Dw

How can I delete a registry key for other program, I just checked my registry and the virus was registered under the same registry key of my other program and now I want to use java as also part of learning java and the method of accessing and deleting a particular registry.

Any suggestion, link, structure code will be appreciated.

Thank you

Java has no direct support for the Windows registry, but it's easy enough to use ProcessBuilder to execute the Windows reg.exe command-line utility to perform registry queries or updates.

It doesn't work

I have applications running every day that use it.
What exactly did you try, and in what way did it fail exactly?

Here is my code.

Process g = new ProcessBuilder("reg.exe", "REG", "DELETE", "HKLM\Software\Microsoft\Windows\CurrentVersion\Test", "/f").start();

I tried it without the "/f" which is force the deletion without asking for confirmation but still it doesn't work. I also tried combining the code but still nothing. Sorry for not formatting the code snip I'm using Cell phone and the panel is not visible that enable me to format the code.

Java String literals treat a back-slash as an escape character. If you want a literal back-slash you need to code two, as in


plus "REG" is just the short form of "reg.exe" from the help file, so you should delete it and just keep the "reg.exe"

See how that goes

Jea that's how I did with double \ I don't know what happened when I posted, I will try out it as you suggested and see how it does.

Oh yeah, Dani's new thread editor tries to be smart about special characters. It makes sense to her, but drives me mad too.
In that case just getting rid of the "REG" should help.
Capturing/echoing the output from the process will help diagnose problems, if you're not already doing that.

Jea that's how I did with double \ I don't know what happened when I posted, I will try out it as you suggested and see how it does.

Sorry for the duplication of posts, I had a problem when I was posting. Thanks that help in deleting the registry key but now the problem is that if I put the program on the same path that was registered meaning "C:\test" if I just put my app on that folder after I've deleted the registry and restart the computer the program still execute automatically I don't know why.

If you were virus infested then it probably did a lot more than make just one registry entry. It's time to use a proper virus removal program (or programs) to do a complete job.

Ok thank you. I guess in that case I will mark this thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.