DoctorWho Posted January 8, 2010 Share Posted January 8, 2010 I've been beating my head trying to resolve a problem and I'm hoping someone may have an answer. I need to insert 1 or 2 lines (most likely 1 line) into the HOSTS file without overwriting any existing entries that may already be in the HOSTS file and I need the script to be able to do this no matter which version of Windows (XP, Vista or 7) the end user has on their PC. Note: The IP(s) and hostname(s) I am trying to insert are known values. I seen several threads about working with the HOSTS file but none of the ones I've read are what I am looking for. Any suggestions would be greatly appreciated. Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 8, 2010 Share Posted January 8, 2010 And where ist your problem? 1. Getting the path 2. Reading the file (maybe obsolete if you just add as last line) 3. adding your stuff 4. done Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
James Posted January 8, 2010 Share Posted January 8, 2010 What about this? $strHost = @SystemDir & "\drivers\etc\hosts" $tcpIP = @IPAddress1 $sWhat = "localhost" $hFile = FileOpen($strHost, 1) ; The 1 parameter just appends to the end of the file FileWrite($hFile, $tcpIP & " " & $sWhat) FileClose($hFile) Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DoctorWho Posted January 8, 2010 Author Share Posted January 8, 2010 What about this? $strHost = @SystemDir & "\drivers\etc\hosts" $tcpIP = @IPAddress1 $sWhat = "localhost" $hFile = FileOpen($strHost, 1) ; The 1 parameter just appends to the end of the file FileWrite($hFile, $tcpIP & " " & $sWhat) FileClose($hFile) Thanks everyone for such quick responses.. James, I'll give your script a try but it looks exactly like what I need. Link to comment Share on other sites More sharing options...
James Posted January 8, 2010 Share Posted January 8, 2010 I'll give your script a try but it looks exactly like what I need.You may need to change this line: FileWrite($hFile, $tcpIP & " " & $sWhat) to FileWrite($hFile, @LF & $tcpIP & " " & $sWhat) if the line doesn't get written to the right place. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DoctorWho Posted January 8, 2010 Author Share Posted January 8, 2010 You may need to change this line: FileWrite($hFile, $tcpIP & " " & $sWhat) to FileWrite($hFile, @LF & $tcpIP & " " & $sWhat) if the line doesn't get written to the right place. Thanks again James, I noticed that the first time I tested the script that it appened to the end of the existing line. It's working great, I just need to get it working for Windows 7 but that should just be it's UAC blocking the changes. Link to comment Share on other sites More sharing options...
James Posted January 8, 2010 Share Posted January 8, 2010 It's working great, I just need to get it working for Windows 7 but that should just be it's UAC blocking the changes.I believe so. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now