So I want to use java to write a program that will edit the host file in windows to add some info to it. When I get home I plan on googling this but would like your feedback also. I'm looking just for a few general suggestion on how to start it or what to put in it. Please don't write it for me, just help.
This should be super freaking easy. I will need to open notepad with elevated privileges in order to edit the host file.
Thanks guys
Kirk
using java to edit host file
- bad_brain
- Site Owner
- Posts: 11636
- Joined: 06 Apr 2005, 16:00
- 19
- Location: In your eye floaters.
- Contact:
Re: using java to edit host file
have a look at this one, it will be definitely needed (imo) because of the security restrictions of Java AND of the OS:
http://download.java.net/jdk7/archive/b ... oller.html" onclick="window.open(this.href);return false;
http://download.java.net/jdk7/archive/b ... oller.html" onclick="window.open(this.href);return false;
Re: using java to edit host file
I'm using eclipse to code it and compile it. I'm stuck good. Would I even have to use a text editor like notepad to make the changes or could I change the file directly some how?
Re: using java to edit host file
You can open any file in Java and Edit it with the changes you want with in your code, without any additional editor like notepad or needed input by a user. Look at File Handling/File IO and the modes associated to those. These are the modes that you would open the file in read, write, read + write, append etc
The problem may be in handling the elevated permissions. However I believe you may be able to bypass this simply by writing a registry value on execution of your script (In a similar fashion to above), or using a launch batch script as an example. You will have to look for that registry value through internet searching.
*cheers
The problem may be in handling the elevated permissions. However I believe you may be able to bypass this simply by writing a registry value on execution of your script (In a similar fashion to above), or using a launch batch script as an example. You will have to look for that registry value through internet searching.
*cheers
Re: using java to edit host file
Couldn't I just have it prompt for the user to ok it some how?
Re: using java to edit host file
The UAC is a Windows OS kernel security feature. You have to create a manifest file with the required user privilege level: http://msdn.microsoft.com/en-us/library/bb756929.aspx
Re: using java to edit host file
I see this is going to be a little more difficult than originally thought. This is a lot of stuff just to append some lines in a file. Good little learning project though.
Re: using java to edit host file
Start by writing the program simply because it's fun (like keep a host file in a user space location for now).
Then you should be able to use eclipse to create the manifest file rather easily, just like you can with Visual Studio these days.
Have a look at this
Then you should be able to use eclipse to create the manifest file rather easily, just like you can with Visual Studio these days.
Have a look at this
Code: Select all
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-35.htm
"The best place to hide a tree, is in a forest"