PDA

View Full Version : سوال: چطوری میشه یک فایل تکست رو باز کرده و بعد از ویرایش ذخیره کنیم؟



hasht.rood
چهارشنبه 25 آبان 1390, 21:48 عصر
سلام دوستان.
این بنده حقیر میخواستم بدونم چطوری میشه این فایل رو با وی بی باز و دو خط به اون اضافه و ذخیره کرد.
آدرس فایل:C:\WINDOWS\system32\drivers\etc
نام فایل:Chosts
متن دیفالت داخل فایل:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

متنی که میخوام به آخرش اضافه کنم:
150.20.20 www.facebook.com
150.20.20 facebook.com
210.4.4.2 www.gmail.com
210.4.4.2 gmail.com

میخوام برنامه این فایل رو باز کرده و این متن رو به آخرش اضافه و ذخیره کنه.
منتظر راهنماییهاتون هستم
شلد و خرم باشین

M.T.P
پنج شنبه 26 آبان 1390, 01:23 صبح
Dim StrText As String
Dim StrFilePath As String
Dim IntFileNumber As Integer

StrText = "150.20.20 www.facebook.com" & vbCrLf & _
"150.20.20 facebook.com" & vbCrLf & _
"210.4.4.2 www.gmail.com" & vbCrLf & _
"210.4.4.2 gmail.com"

StrFilePath = "C:\WINDOWS\system32\drivers\etc\hosts"
IntFileNumber = FreeFile()

Open StrFilePath For Append As IntFileNumber
Print #IntFileNumber, vbCrLf & StrText
Close IntFileNumber

sajjad_india
پنج شنبه 26 آبان 1390, 12:17 عصر
MTP كارت تو اصلا درسته بخدا