VBScript
Option
Explicit
Dim ShellObj, sCathiLoc, sIniFile, sLeft, sFind, pos, boolCathiMode, boolUnicodeMode
set ShellObj = CreateObject ( " WScript.Shell " )
sCathiLoc = EES( " %CathiDir% " )
sIniFile = FileToString(sCathiLoc + " \BindingOutForBug193413.xml " )
' Replace the host name of Microsoft.Test.Ebiz.OpsMan.Scenarios.EquityLoan.EquityLoanOrchestration to none
sFind = " <Host Name=""BizTalkServerApplication"" NTGroupName=""BizTalk Application Users"" Type=""1"" Trusted=""true"" /> "
pos = InstrRev (sIniFile, sFind)
sLeft = Left (sIniFile, pos - 1 )
sIniFile = Replace (sIniFile, sFind, " <Host xsi:nil=""true"" /> " , pos - 1 , 1 )
sIniFile = sLeft + sIniFile
Call StringToFile(sIniFile, sCathiLoc + " \BindingInForBug193413.xml " )
' ************************************************************
' Utility function to get a enviroment location
' ************************************************************
Function EES(EnvVar)
EES = ShellObj.ExpandEnvironmentStrings(EnvVar)
End Function
' ************************************************************
' Utility function to read a file into a string
' ************************************************************
Function FileToString(sPath)
Dim fso, f
Const ForReading = 1
Const TristateTrue = - 1
Set fso = CreateObject ( " Scripting.FileSystemObject " )
if fso.FileExists(sPath) = 0 then
if not boolCathiMode then
wscript.echo " Input file doesn't exist: ' " & sPath & " ' "
else
Call objLog.LogFail( CStr ( " Input file doesn't exist: ' " & sPath & " ' " ))
end if
WScript.Quit( 1 )
end if
if boolUnicodeMode then
Set f = fso.OpenTextFile(sPath, ForReading, false , TristateTrue)
else
Set f = fso.OpenTextFile(sPath, ForReading)
end if
FileToString = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
end Function
' ************************************************************
' Utility function to write a string to a file
' ************************************************************
Sub StringToFile(sString, sPath)
Dim fso, f, hHandle
Set fso = CreateObject ( " Scripting.FileSystemObject " )
if boolUnicodeMode then
Set f = fso.CreateTextFile(sPath, true , true )
else
Set f = fso.CreateTextFile(sPath, true )
end if
f.Write sString
f.Close
if Err.number <> 0 then
PrintWMIErrorthenExit Err.Description, Err.Number
else
if not boolCathiMode then
wscript.echo " Output file is created: ' " & sPath & " ' "
else
Call objLog.LogInfo( CStr ( " Output file is created: ' " & sPath & " ' " ))
end if
end if
Set f = Nothing
Set fso = Nothing
end Sub
Dim ShellObj, sCathiLoc, sIniFile, sLeft, sFind, pos, boolCathiMode, boolUnicodeMode
set ShellObj = CreateObject ( " WScript.Shell " )
sCathiLoc = EES( " %CathiDir% " )
sIniFile = FileToString(sCathiLoc + " \BindingOutForBug193413.xml " )
' Replace the host name of Microsoft.Test.Ebiz.OpsMan.Scenarios.EquityLoan.EquityLoanOrchestration to none
sFind = " <Host Name=""BizTalkServerApplication"" NTGroupName=""BizTalk Application Users"" Type=""1"" Trusted=""true"" /> "
pos = InstrRev (sIniFile, sFind)
sLeft = Left (sIniFile, pos - 1 )
sIniFile = Replace (sIniFile, sFind, " <Host xsi:nil=""true"" /> " , pos - 1 , 1 )
sIniFile = sLeft + sIniFile
Call StringToFile(sIniFile, sCathiLoc + " \BindingInForBug193413.xml " )
' ************************************************************
' Utility function to get a enviroment location
' ************************************************************
Function EES(EnvVar)
EES = ShellObj.ExpandEnvironmentStrings(EnvVar)
End Function
' ************************************************************
' Utility function to read a file into a string
' ************************************************************
Function FileToString(sPath)
Dim fso, f
Const ForReading = 1
Const TristateTrue = - 1
Set fso = CreateObject ( " Scripting.FileSystemObject " )
if fso.FileExists(sPath) = 0 then
if not boolCathiMode then
wscript.echo " Input file doesn't exist: ' " & sPath & " ' "
else
Call objLog.LogFail( CStr ( " Input file doesn't exist: ' " & sPath & " ' " ))
end if
WScript.Quit( 1 )
end if
if boolUnicodeMode then
Set f = fso.OpenTextFile(sPath, ForReading, false , TristateTrue)
else
Set f = fso.OpenTextFile(sPath, ForReading)
end if
FileToString = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
end Function
' ************************************************************
' Utility function to write a string to a file
' ************************************************************
Sub StringToFile(sString, sPath)
Dim fso, f, hHandle
Set fso = CreateObject ( " Scripting.FileSystemObject " )
if boolUnicodeMode then
Set f = fso.CreateTextFile(sPath, true , true )
else
Set f = fso.CreateTextFile(sPath, true )
end if
f.Write sString
f.Close
if Err.number <> 0 then
PrintWMIErrorthenExit Err.Description, Err.Number
else
if not boolCathiMode then
wscript.echo " Output file is created: ' " & sPath & " ' "
else
Call objLog.LogInfo( CStr ( " Output file is created: ' " & sPath & " ' " ))
end if
end if
Set f = Nothing
Set fso = Nothing
end Sub
-----------参考网站------------
http://en.wikipedia.org/wiki/VBScript
Wiki
http://www.w3school.com.cn/vbscript/index.asp
VBScript教程@W3School
http://msdn.microsoft.com/en-us/library/k9z80300(v=VS.85).aspx
Replace Method (VBScript)@MSDN
http://msdn.microsoft.com/en-us/library/hsxyczeb(v=VS.85).aspx
InStrRev Function@MSDN
http://forum.openvpn.eu/viewtopic.php?f=25&t=7266&start=0
Example of ShellObj.ExpandEnvironmentStrings