Sunday, March 06, 2005

vbscript to change several config files

My environment is using an separeted db server. So i created a scipt where i can just copy all db's and afterwards i'm using a vb script to modify all web.config

Const FilePath1 = "D:\DotNet\Indexus\WsAppAccount\"
Const FilePath2 = "D:\DotNet\Indexus\WsAppApplication\"
Const FilePath3 = "D:\DotNet\Indexus\WsAppBilling\"
Const FilePath4 = "D:\DotNet\Indexus\WsAppFailures\"
Const FilePath5 = "D:\DotNet\Indexus\WsAppLog\"
Const FilePath6 = "D:\DotNet\Indexus\WsAppNotification\"
Const FilePath7 = "D:\DotNet\Indexus\WsAppStatistic\"
Const FilePath8 = "D:\DotNet\Indexus\WsAppSupplier\"

Const ForReading = 1
Const ForWriting = 2

Dim strFrom, strTo

strFrom = "192.168.1.34"
strTo = "localhost"

ChangeDB strFrom, strTo, FilePath1 + "Web.config"
ChangeDB strFrom, strTo, FilePath2 + "Web.config"
ChangeDB strFrom, strTo, FilePath3 + "Web.config"
ChangeDB strFrom, strTo, FilePath4 + "Web.config"
ChangeDB strFrom, strTo, FilePath5 + "Web.config"
ChangeDB strFrom, strTo, FilePath6 + "Web.config"
ChangeDB strFrom, strTo, FilePath7 + "Web.config"
ChangeDB strFrom, strTo, FilePath8 + "Web.config"

'Msgbox "All config files changed to localhost", 0, "Localhost DB Script"

Sub ChangeDB(strFrom, strTo, FilePath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FilePath, ForReading)

strText = objFile.ReadAll objFile.Close
strNewText = Replace(strText, strFrom, strTo)

Set objFile = objFSO.OpenTextFile(FilePath, ForWriting)
objFile.WriteLine strNewText objFile.Close

set objFile = nothing
set objFSO = nothing

End Sub

No comments:

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge