Mman Posted October 14, 2004 Posted October 14, 2004 Hi.I need a script or a command that can be used in a script that will add a line to the hosts file of a computer with the user's permission.any ideas?thanks.M.
prathapml Posted October 14, 2004 Posted October 14, 2004 Do you specifically need the user to say "yes" ? Because if not, then it'd be simple to directly add what you want, into the host file.But if you do want user to say yes, this will do the task you want, copy/paste into notepad, and save as .BAT:@echo offTITLE Modifying your HOSTS fileCOLOR 85ECHO.:LOOPSET Choice=SET /P Choice="Do you want to modify HOSTS file ? (Y/N)"IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%ECHO.IF /I '%Choice%'=='Y' GOTO ACCEPTEDIF /I '%Choice%'=='N' GOTO REJECTEDECHO Please type Y (for Yes) or N (for No) to proceed!ECHO.GOTO Loop:REJECTEDECHO Your HOSTS file was left unchanged >> %systemroot%\Temp\yourinstall.logECHO Finished.GOTO END:ACCEPTEDECHO Carrying out requested modifications to your HOSTS fileecho 127.0.0.1 local host >> %WinDir%\system32\drivers\etc\hostsECHO Finished.GOTO END:ENDECHO.EXITIts quite self-explanatory. While the rest of the command-line script will do your yes/no part, the below line is what does the actual modification.echo 127.0.0.1 local host >> %WinDir%\system32\drivers\etc\hostsThat is, you can "echo" whatever line you want into the HOSTS file, using the double-forward symbol. The location of the hosts file above, is given for win2k/XP/2k3. For win95/98/ME, its located at a different place.
Mman Posted October 15, 2004 Author Posted October 15, 2004 thanks alot!the scripy wroks great. I only had to remove the @echo off at the beginning of the code.GREAT!NOW - is there any way to run this script automatically through html / xml code so that everyone browsing a certain website will receive the option to run the code? M.
babai93 Posted January 14, 2012 Posted January 14, 2012 Hi, Mr.Prathapml,Nice script, thanks.in my scenario I logged in is USER Profile, so how could I run the batch file without having the Admin rights of Admin Password. if i have the Password than I can run it as Administrator. if not than how to do this with the help of Command line which can be embed within the BATCH (.bat) file?Please let us.Regards,Babai Dutta | 9903010393
IcemanND Posted January 14, 2012 Posted January 14, 2012 The HOSTS file is a protected file and can not be modified by a non-administrator user. You would have to run the script as an administrator user in order to modify it.
mbaird Posted September 6, 2013 Posted September 6, 2013 prathapml,Is there an automated way to remove a line from a hosts file?
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now