VBS Delete Text from File ?

Hi,

I have a VBS script that creates a VPN connection on the system. Works great. What I want to do now is create another script that will remove that VPN connection that I just created. To do this I want to be able to delete certain text from the rasphone.pbk file. Anyone have any idea how to do this ? Below is the an example of what I am doing to create the connection, all I need to be able to do is the reverse.

Dim filesys, vpnfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set vpnfile= filesys.OpenTextFile("C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk", 8)
vpnfile.WriteLine "[New VPN Connection]"
vpnfile.WriteLine "Encoding=1"
vpnfile.WriteLine "Type=2"
vpnfile.WriteLine "AutoLogon=0"
vpnfile.WriteLine "UseRasCredentials=1"
vpnfile.WriteLine "DialParamsUID=167104187"
vpnfile.WriteLine "Guid=42B083324A9KGE46B092E887F0F0677C"
vpnfile.WriteLine "BaseProtocol=1"
vpnfile.WriteLine "VpnStrategy=2"
vpnfile.WriteLine "ExcludedProtocols=0"
vpnfile.Close

How can I go back into that text file and Remove those lines I just created ? Any help would be greatly appreciated. Thanks!
kasowitzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dasmcseCommented:
I would read the rasphone.pbk file line by line copying each line to a temp file and ignoring the lines in question. Then close both files. Then copy the temp over rasphone.pbk.
0
kasowitzAuthor Commented:
How would I go about doing that in VBS ?  How would I designate which lines to ignore ? Would you mind showing me a little example code please ?  Thanks.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Dim filesys, vpnFile, vpnContents, vpnSplit

Set filesys = CreateObject("Scripting.FileSystemObject")

Set vpnFile= filesys.OpenTextFile("C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk", 1)
vpnContents = vpnFile.ReadAll
vpnFile.Close

vpnSplit = Split(vpnContents, "[New VPN Connection]")

Set vpnFile= filesys.OpenTextFile("C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk", 2)
vpnFile.Write(vpnFile(0))
vpnFile.Close
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
This assumes that your "[New VPN Connection]" section is at the end of the file and that there is nothing after it...
0
fostejoCommented:
kasowitz,

I'd suggest the simplest way is to call rasphone with the -r parameter and the name of the connection to delete; something similar to..

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "rasphone -r TheNameOfYourConnection"

cheers,
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.