Vlearns
asked on
simple question
i am new to vb:
this is what i want to do
i have a combobox with a list of items:
each of these represent domain names
a1
a2
a3
a4
a5
i also have a command button called 'execute'
now when user selects on either of this , say a1, and hits 'execute' my application needs to go to
C:\WINDOWS\system32\driver s\etc
and add the entry to the hosts file
such as
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
similarly if user clicks on a2 and hits execute
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
i now the ip addresses vv.xx.yy.zz etc, so i need to know how to do file handling in vb.
this is what is intend to do...
when user selects one of a1,a2 etc,
backuo hosts to host.bak
delete hosts
create a new file 'hosts' using vb
programmatically write
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
to the hosts file
close the file.
please guide me how i can achieve this VB programmatically. i am not familiarwith VB programming constructs.
this is what i want to do
i have a combobox with a list of items:
each of these represent domain names
a1
a2
a3
a4
a5
i also have a command button called 'execute'
now when user selects on either of this , say a1, and hits 'execute' my application needs to go to
C:\WINDOWS\system32\driver
and add the entry to the hosts file
such as
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
similarly if user clicks on a2 and hits execute
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
i now the ip addresses vv.xx.yy.zz etc, so i need to know how to do file handling in vb.
this is what is intend to do...
when user selects one of a1,a2 etc,
backuo hosts to host.bak
delete hosts
create a new file 'hosts' using vb
programmatically write
vv.xx.yy.zz a1.go.domain.com
vv1.xx1.yy1.zz1 a1.see.domain.com
to the hosts file
close the file.
please guide me how i can achieve this VB programmatically. i am not familiarwith VB programming constructs.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the hosts file should be just 'hosts' and not hosts.txt
do you think the opentextfile can only create the hosts file with hosts.txt?
i will try and see
do you think the opentextfile can only create the hosts file with hosts.txt?
i will try and see
ASKER
got this error
Object Variable or With Block Variable not set
at
.CopyFile "C:\WINDOWS\system32\drive rs\etc\hos ts", "C:\WINDOWS\system32\drive rs\etc\hos ts.bak", True
shouldnt fso be initialized to somethin?
Object Variable or With Block Variable not set
at
.CopyFile "C:\WINDOWS\system32\drive
shouldnt fso be initialized to somethin?
ASKER
solved the problem:
should have been
Dim fso As New Scripting.FileSystemObject
instead ogf
Dim fso As Scripting.FileSystemObject
ASKER
can someone tell me how to write this to file
.WriteLine "123.111.222.333 & Item & .domain.com "
where the output should be
123.111.222.333 ab.domain.com
where Item="ab" ????????????????????????
<<<<can someone tell me how to write this to file .WriteLine "123.111.222.333 & Item & .domain.com "
.WriteLine "123.111.222.333 " & Combo1.List(Combo1.ListInd ex) & ".domain.com"
.WriteLine "123.111.222.333 " & Combo1.List(Combo1.ListInd
Dim sSelectedItem as String
sSelectedItem = Combo1.List(Combo1.ListInd