vbscript替换文本 - 一个工作两个打破整个事情

Tra*_*vis 2 vbscript

我希望此脚本替换同一文本文件中的两个值而不是一个.但是,如果我取消注释第12行,它会破坏脚本.我是否必须将其转换为循环,还是可以进行多次替换?

Sub ReplaceTxt()
'Writes values we got earlier to our unattend file       '
Const ForReading = 1
Const ForWriting = 2

   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile(strSIFpath, ForReading)

   strText = objFile.ReadAll
   objFile.Close
   strNewText = Replace(strText, "***COMPNAME***", strCompname)
 '  strNewText = Replace(strText, "***Winkey***", strPoductkey)    '

   Set objFile = objFSO.OpenTextFile("C:\$WIN_NT$.~BT\winnt.sif", ForWriting)
   objFile.WriteLine strNewText
   objFile.Close
End Sub
Run Code Online (Sandbox Code Playgroud)

Fre*_*örk 6

我想你会想要对第一个返回的字符串进行第二次替换:

strNewText = Replace(strText, "***COMPNAME***", strCompname)
strNewText = Replace(strNewText , "***Winkey***", strPoductkey)
Run Code Online (Sandbox Code Playgroud)

否则您将失去第一个替换,并且只有第二个替换将出现在结果中.