VBScript

VBScript

OptionExplicit

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) =0then
ifnot boolCathiMode then
wscript.echo
"Input file doesn't exist: '"& sPath &"'"
else
Call objLog.LogFail(CStr("Input file doesn't exist: '"& sPath &"'"))
endif
WScript.Quit(
1)
endif

if boolUnicodeMode then
Set f = fso.OpenTextFile(sPath, ForReading, false, TristateTrue)
else
Set f = fso.OpenTextFile(sPath, ForReading)
endif

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)
endif

f.Write sString
f.Close

if Err.number <>0then
PrintWMIErrorthenExit Err.Description, Err.Number
else
ifnot boolCathiMode then
wscript.echo
"Output file is created: '"& sPath &"'"
else
Call objLog.LogInfo(CStr("Output file is created: '"& sPath &"'"))
endif
endif

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

posted on 2014-10-05 10:58  浩然119  阅读(270)  评论(0编辑  收藏  举报