Jump to content

Open hosts file ?


MrVietA2
 Share

Recommended Posts

My OS is Win7 and it works perfectly!

#RequireAdmin

 _HostWrite("127.0.0.0", "Computer", 1)

$asHost = _HostRead()
_ArrayDisplay($asHost, "HostFile")

_HostDelete("127.0.0.0", "Computer")

$asHost = _HostRead()
_ArrayDisplay($asHost, "HostFile")

João Carlos.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Inside the source of the UDF, you will see these lines:

;
; Skip comment lines proceeded by: #
If StringLen($Line) < 10 Or StringRegExp(StringStripWS($Line, 8), "\A#") Then ContinueLoop
;
Your hosts file only have comments?

João Carlos.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Inside the source of the UDF, you will see these lines:

;
; Skip comment lines proceeded by: #
If StringLen($Line) < 10 Or StringRegExp(StringStripWS($Line, 8), "\A#") Then ContinueLoop
;
Your hosts file only have comments?

João Carlos.

I don't understand , i want to open hosts file with notepad like #9, can you help me ? Thanks

Link to comment
Share on other sites

Why would you use _RunDOS over Run or ShellExectute? No includes needed with either of the others, and _RunDOS should only be used for things that won't work any other way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Why are you so intent on editing your host file with an AutoIt script? No, we won't give you "personal" service with instant messenger.

You need to post your code and explain what you have in mind. Saying "I want to open my HOST file isn't enough. WHY you want to do it and the purpose of doing it would explain much.

Link to comment
Share on other sites

One of my very first released AutoIt Scripts was a HOST file manager, so yes; there are legitimate reasons for working with the host file.

@MrVietA2

You use FileOpen(), File Read(), FileClose() the same way for Host as you do for any other file and all the help required for that is in the Help file. For simply reading it you don't need FileOpen() at all; just go with FileRead().

There are also not so legit reasons for messing with that file and if you get caught doing any of those it won't be a nice outcome. Understandably people are suspicious when you start playing with certain files. Of course the easiest way for people to avoid problems with HOST is to keep it regularly updated and have a look at the checksum periodically.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Why are you so intent on editing your host file with an AutoIt script? No, we won't give you "personal" service with instant messenger.

You need to post your code and explain what you have in mind. Saying "I want to open my HOST file isn't enough. WHY you want to do it and the purpose of doing it would explain much.

I only want to open hosts file and want user can edit it :graduated:, nothing else ;) !

This is my code :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
 
$Form1 = GUICreate("Open hosts file !", 316, 130, 407, 229)
$Label1 = GUICtrlCreateLabel("OPEN THE HOSTS FILE IN WINDOWS", 16, 24, 285, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman")
GUICtrlSetColor(-1, 0x008000)
$Button1 = GUICtrlCreateButton("OPEN", 80, 56, 153, 57)
GUICtrlSetFont(-1, 11, 800, 0, "Times New Roman")
GUISetState(@SW_SHOW)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _open()
    EndSwitch
WEnd
 
Func _open()
ShellExecute(@SystemDir & "\Notepad.exe", @SystemDir & "\Drivers\Etc\hosts", "")
EndFunc

@GEOsoft : I know how to do this :), thanks for that ;)

THANKS ALL

Edited by MrVietA2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...