就是修改hosts的内容来达到屏蔽某网站

解决方案 »

  1.   

    var
      hosts:TStringList;
      hostspath:string;
      str1:string;
    begin
      hosts := TStringList.Create;
      hostspath := GetEnvironmentVariable('SystemRoot') + '\System32\drivers\etc\hosts';
      hosts.LoadFromFile(hostspath);
      str1 := #9 + '127.0.0.1' + #9 + '你要屏蔽的域名';
      hosts.SaveToFile(hostspath);
      hosts.Free;
    end;
      

  2.   

    上面忘写了一行 汗var 
      hosts:TStringList; 
      hostspath:string; 
      str1:string; 
    begin 
      hosts := TStringList.Create; 
      hostspath := GetEnvironmentVariable('SystemRoot') + '\System32\drivers\etc\hosts'; 
      hosts.LoadFromFile(hostspath); 
      str1 := #9 + '127.0.0.1' + #9 + '你要屏蔽的域名'; 
      hosts.add(str1);
      hosts.SaveToFile(hostspath); 
      hosts.Free; 
    end; 
      

  3.   

    删了?  汗。。 那系统还能用吗?  具体我不晓得.... 但是应付这种状况加个try就可以了var 
      hosts:TStringList; 
      hostspath:string; 
      str1:string; 
    begin 
      hosts := TStringList.Create; 
      hostspath := GetEnvironmentVariable('SystemRoot') + '\System32\drivers\etc\hosts'; 
      try
        hosts.LoadFromFile(hostspath); 
      finally
        str1 := #9 + '127.0.0.1' + #9 + '你要屏蔽的域名'; 
        hosts.add(str1); 
        hosts.SaveToFile(hostspath); 
        hosts.Free; 
      end;
    end;
      

  4.   

    hosts可以被删除,话说很久以前用VB写过一个Hosts的玩意,只可惜现在VB忘光了……
    可以先用openfile打开,根据返回值进行判断,