Jump to content
Sign in to follow this  
MrVietA2

Open hosts file ?

Recommended Posts

Hi everyone !

I have a 1 question : " How can I open hosts file in windows with autoit code ? ". I tried by some other program but failed ! Help me plz ! Thank you ! :graduated:

Share this post


Link to post
Share on other sites

Hi, try this:

João Carlos.

I include the au3 file and use _HostRead("C:\Windows\System32\drivers\etc\hosts") but it doesn't work . Help me, thanks

Share this post


Link to post
Share on other sites

You must to be use this directive: #RequireAdmin

Compile your script and see the result!

João Carlos.

I try but it doesn't work, can you help me on Yahoo ?

Y!M : destinystars_neverstop@yahoo.com

Thanks !

Edited by MrVietA2

Share this post


Link to post
Share on other sites

Doubts only here, and the UDF was only tested on XP!

João Carlos.

My OS is windows 7 :graduated:, what else ? ;) How can I do that ?

Edited by MrVietA2

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Simple:

ShellExecute(@SystemDir & "\Notepad.exe", @SystemDir & "\Drivers\Etc\hosts", "")

João Carlos.

Oh, it work ! Thanks !

Can use :

#include <Process.au3>

_RunDOS("start %windir%\notepad.exe %windir%\system32\drivers\etc\hosts")

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I have an other question : " How can I make a hosts file with FileOpen() ? " . Thanks so much

Edited by MrVietA2

Share this post


Link to post
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.

Share this post


Link to post
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!"

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I compile my script to exe file but it can decompile . I have 1 question : " How can I protect my source not decompile ? ". Thanks :graduated:

P/s : My English is bad, sorry about that ;)

Edited by MrVietA2

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By WoodGrain
      Hi All,
      Trying to open windows explorer to a WebDav location and it's not working quite how I want, on the computers it is setup as a "network location" (as opposed to a "mapped drive", and this unfortunately can't be changed), the "Data" WebDav folder sits directly under "This PC" if that's an easier way to get to it. any suggestions as to what I can correct to get the 2nd example to work?
      ; This works, but I'm trying to avoid this as users normally see the URL style in the 2nd example below $folderToOpen = "\\mycompany.sharepoint.com@SSL\DavWWWRoot\Data" Run("Explorer.exe " & $folderToOpen) ; This does not work, it tries to open the WebDav url in the default web browser $folderToOpen = "https://mycompany.sharepoint.com/Data" Run("Explorer.exe " & $folderToOpen) ShellExecute also opens it in the default browser.
      Saw _WinAPI_ShellOpenFolderAndSelectItems but couldn't get the 2nd example to work.
      If I manually open Windows Explorer and paste in https://mycompany.sharepoint.com/Data it loads the WebDav directory without issue.
      If I have to use the pathing from the first example it is fine, just trying to give users a familiar experience.
      Thanks!
    • By stafe
      I want to write a script to toggle the opening and closing of a pdf file.
      For example if i have a flie called myFile.pdf I want the script to open/load it.  However if myFile.pdf is open then i want the same script to close it. 
      Could someone please tell me how I can know if the pdf file is open/loaded?
      Thank you 
      Simon
    • By Jefrey
      Events-based UDF to help on handling one or more TCP connections
    • By Jefrey
      Hi guys!
      I'm having a trouble with TCPAccept() on compiled scripts.
      This script I made to test:
      #include <Debug.au3> _DebugSetup() TCPStartup() $Main = TCPListen("0.0.0.0", 8081) _DebugOut("TCPListen output: " & $Main) While True $ac = TCPAccept($Main) _DebugOut("TCPAccept return: " & $ac) If $ac <> -1 Then _DebugOut("There's someone out here!") TCPSend($ac, "hi") EndIf WEnd Works fine if I run it by pressing F5 on SciTe window.

      But if I compile it and then execute the executable file, it does not work. Instead, NetCat tells me that the connection timed out (I've tested other clients as well):

      I've checked if the port is really opened, if I really can open it, if there is other software using that port, but everything showed that it should connect.
      Btw, netstat -an shows that the port is really listening (when I execute my file). It listens, but does not accept.

      I use no antivirus software (I use this Windows installation for coding only) and Windows Firewall is disabled. I've tried, anyway, allowing my exe file on Firewall rules, but it also did not work. Running as administrator also did not help.
      I believe it's a Windows (Firewall?) bug rather than an AutoIt bug. How can I manage to solve this?
      Thanks in advance.
       
    • By JohnOne
      I cannot find any concrete info on this.
      What is and is not valid in a windows (vista+) hosts file?
      0.0.0.0 http://www.domain.com (I know for example that http:// is not valid)
      0,0,0,0 www.domain.com 0.0.0.0 sub.domain.com 0.0.0.0 sub.sub.domain.com 0.0.0.0 domain_name.com 0.0.0.0 domain-mane.com 0.0.0.0 1domain.com 0.0.0.0 _domain.co 0.0.0.0 2
×
×
  • Create New...