Trên đây là đoạn code nè em.
http://binhphuoc.org/diendan/visual-...html#post59691
Đây là source của công cụ trên
Code:private void bt_append_Click(object sender, EventArgs e) { try { FileStream hosts_file = null; hosts_file = File.Open(@"C:\WINDOWS\system32\drivers\etc\hosts", FileMode.Append, FileAccess.Write); StreamWriter write = new StreamWriter(hosts_file); string str_ip = txt_ip.Text; string str_site = txt_site.Text; //write.WriteLine("#"); write.WriteLine("{0} \t {1}", str_ip, str_site); write.Close(); hosts_file.Close(); } catch(Exception ex) { MessageBox.Show("Phat sinh loi: \n\n {0}", ex.ToString()); } } private void bt_restore_Click(object sender, EventArgs e) { try { FileInfo hosts_file = new FileInfo(@"C:\WINDOWS\system32\drivers\etc\Kentji.Hosts"); hosts_file.CopyTo(@"C:\WINDOWS\system32\drivers\etc\hosts", true); MessageBox.Show("Restore Complete","Make by Kentji"); } catch (Exception ex) { MessageBox.Show("Phat sinh loi: Khong the ghi de len tap tin \n\n"+ ex.ToString(),"Loi"); } } private void Form1_Load(object sender, EventArgs e) { } private void bt_Backup_Click(object sender, EventArgs e) { try { FileInfo hosts_file = new FileInfo(@"C:\WINDOWS\system32\drivers\etc\hosts"); hosts_file.CopyTo(@"C:\WINDOWS\system32\drivers\etc\Kentji.Hosts", true); FileStream hosts_file1 = null; hosts_file1 = File.Open(@"C:\WINDOWS\system32\drivers\etc\hosts", FileMode.Append, FileAccess.Write); StreamWriter write = new StreamWriter(hosts_file1); write.WriteLine("# \t Backup from line | Kentji \t #"); write.Close(); hosts_file1.Close(); MessageBox.Show("Backup Complete","BPIT"); } catch(Exception ex) { MessageBox.Show("Phat sinh loi: Khong the ghi de len tap tin \n\n{0}", ex.ToString()); } } private void button1_Click(object sender, EventArgs e) { try { FileStream hosts_file = new FileStream(@"C:\WINDOWS\system32\drivers\etc\hosts", FileMode.Open, FileAccess.Read); StreamReader rdr = new StreamReader(hosts_file); string s = rdr.ReadToEnd(); MessageBox.Show(s,"Binhphuoc.Org"); hosts_file.Close(); } catch(Exception ex) { MessageBox.Show("Phat sinh loi: \n\n {0}"+ ex.ToString(),"Phat sinh loi"); } }
█ Maidep.com - Không mặc váy thì thôi - Đã mặc là phải ngắn !
█ Binhphuoc.Org - [DL] Windows 7 SP1, [DL] Yahoo!10 Tiếng Việt, LAMPP on CentOS with yum, Binhphuoc Yahoo Tool
█ Follow me on Facebook, Yume, Y!Blog, BPIT Profile
█ Be good, be bad, be myself !
Mùa đông tuy lạnh nhưng rất lãng mạng. Nắng mùa đông yếu nhưng đủ làm ấm trái tim một ai đó
Đừng khép chặt trái tim mình, hãy mở rộng và đón chờ những giây phút ngọt ngào ...
Muốn làm cái gì thì phải tìm hiểu về nó trước đã, cứ chụp giựt thế này thì đến bao giờ mới khá nổi.
bt_append_Click và bt_restore_Click tên 2 cái Button Control trong VB6. Còn làm sao để có 2 cái buttom trên thì tự tìm hiểu đi.
VB6 không còn mấy ai lập trình trên nó nữa nên ko có cài, ko có cái để hướng dẫn cho chú.
Anh không chơi VB, anh viết bằng C# đấy chứ, nhưng em thích dùng VB thì cũng được (với điều kiện em phải biết VB ^^)
Tạo 2 Textbox đặt tên là txt_ip và txt_site
Tạo các button là bt_append, bt_backup, bt_restore theo nhu cầu
Sau đó nhập code cho từng button
Sử dụng thư viện System.IO nữa nha
█ Maidep.com - Không mặc váy thì thôi - Đã mặc là phải ngắn !
█ Binhphuoc.Org - [DL] Windows 7 SP1, [DL] Yahoo!10 Tiếng Việt, LAMPP on CentOS with yum, Binhphuoc Yahoo Tool
█ Follow me on Facebook, Yume, Y!Blog, BPIT Profile
█ Be good, be bad, be myself !
Mùa đông tuy lạnh nhưng rất lãng mạng. Nắng mùa đông yếu nhưng đủ làm ấm trái tim một ai đó
Đừng khép chặt trái tim mình, hãy mở rộng và đón chờ những giây phút ngọt ngào ...
VB6 khai báo hoàn toàn khác C# . Với đoạn code trên mà đem dán vào VB6 thì làm sao mà nó chạy dc
Hì thank 2 anh nhé, e mới mò mẫm nên ko biết rõ :p
Có 1 người đang xem chủ đề. (0 thành viên và 1 khách)