1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] Hosts file visual Basics.

Discussion in 'Visual Basic ( VB )' started by malikite, Dec 30, 2009.

  1. malikite

    malikite New Member

    Joined:
    Dec 27, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    Could anyone please help me, I need a code which after the press of a button inputs certain IP Addresses in the Hosts file.

    Please help,

    Thanks In advance :D
     
  2. malikite

    malikite New Member

    Joined:
    Dec 27, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I can't seem to edit my post so im just going to add this one.

    What I really what to do is the hosts file located in C:\windows\system32\drivers\etc\hosts, which is used to map hostnames to ip addresses,I need to input data or a line.
    eg: # 123.412.423:232 ww.sdwxc.com
    into it, i can only input data when it is in .txt format but the hosts file is in someother format.

    What I really need is when i click a button on a program I add a line into the hosts file to block a particular site,but after its done it should be back to its original format.

    Does anyone have any idea how to do this?
     
  3. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    i 'vce no idea what you are trying to do
    but you can always open any kind of file in to a text stream using the
    my.computer.readAlltext()
    function
    but i muz say that theres a chance of havng gibberish instead what you want
    after you do your changes use
    my.computer.writeAllext()

    to write back
    you can use the io class as well
     
    shabbir likes this.
  4. rahul_mawana

    rahul_mawana New Member

    Joined:
    Apr 4, 2009
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    yes u can do this,just open host file in append mode as text file nd write in it what u want to, before sometimes i did it to make a simple virus.if u do nt able to do this then tell me i will write full code here
     
  5. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    do this:--

    Code:
    Private Sub Command1_Click()
    fileloc = "C:\windows\system32\drivers\etc\hosts"
    Open fileloc For Append As #1
    Print #1, "212.123.23.3    www.xyz.com"
    Close #1
    End Sub
    
     
  6. rahul_mawana

    rahul_mawana New Member

    Joined:
    Apr 4, 2009
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    this won't work if windows instalation drive is not C:\,
    so for knowing windows instalation drive u will have to use a API "GetWindowsDirectory
     

Share This Page