Archive: Making an entry to the hosts file


Making an entry to the hosts file
Hello all
I am trying to add an entry to the hosts file using the modern UI..
But I am not sure how to go about this, have been looking in the manual for quite some time now. Without luck
Can anybody help out here with a snipplet of script for this?

Thanks in advance

Lars


Use FileOpen, FileWrite, FileRead and FileClose. See the Archive for examples.


Hosts file
"Use FileOpen, FileWrite, FileRead and FileClose. See the Archive for examples."

Thanks for the reply, this is what I have been doing, especially in the filesection of the archive, and also in the examples, and I cannot find some code I can use. I know I have to use the 4 functions you mention above, but my skills in NSIS is still too small... So I was hoping for sode code.. Someone must have tried this..

Wbr
Lars


The Archive is full of file altering code randing from deleting a certain line to replacing a certain strings across multiple lines. Just search for FileWrite using the search function and you're bound to found something that could help.


Thanks, found some usefull information, and appended this to project,however.. If you see the example below, when I write to "somefile.txt" it works, but when writing to the hosts file it does not... Any ideas?

; Write to hosts file
;FileOpen $4 "$DESKTOP\SomeFile.txt" a
FileOpen $4 $SYSDIR\drivers\etc\hosts a
FileSeek $4 0 END
FileWrite $4 "$\r$\n" ; we write a new line
FileWrite $4 "Test"
FileWrite $4 "$\r$\n" ; we write an extra line
FileClose $4 ; and close the file

An additional question.. I think mosts hosts file per default is read only, do I have to change attributes as well..


Yes, a file can't be opened for writing when its read only atrribute is set. Remove it using SetFileAtrributes.


i want to edit a ini file. on host the file is readonly mode
i did the following
IfFileExists "c:\bos.ini" +3 0
WriteIniStr "c:\bos.ini" "operating systems" "c:\asd" '"aasd"'

than also it does not write anything to the ini file..

please help


your relative jump for IfFileExists is away (+3) from the WriteINIStr instruction, according to your code above, you're writing to the file if does not exist (0).