CRT可以在Session下修改Properties,从而批量修改配置文件
- '2012年12月29日19:06:59 用于修改Xshell登陆文件
- On Error Resume Next
- Const ForReading = 1
- Const ForWriting = 2
- Const Forappending = 8
- Dim check
- 'check = "ReadOnly"
- GETINFO = inputbox("请输入”passwd,enablepasswd” :" & vbcrlf & _
- "此脚本请在登陆文件所在目录运行" & vbcrlf & _
- "登录名默认admin,如有改变请自行修改脚本" ,_
- month(NOW) &"月" & day(NOW)& "日"&" "&"修改自动登陆文件" ,_
- "y7Gw$ka6*,(UhFg2g!X")
- ArryPwd = split(GETINFO ,",")
- passwd = ArryPwd(0)
- enablepasswd = ArryPwd(1)
- Set fso = CreateObject("Scripting.FileSystemObject")
- path = fso.GetFile(Wscript.ScriptFullName).ParentFolder
- 'msgbox ShowFileList(path)
- ShowFileList(path)
- Set NameList = fso.OpenTextFile(".\name.ini")
- DO While NameList.AtEndOfStream <> True
- INIFileName = NameList.ReadLine
- if INIFileName <>"" then
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_0",":"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_0","admin"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_1",":"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_1",passwd
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_2",">"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_2","enable"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_3",":"
- Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_3",enablepasswd
- end if
- loop
- msgbox "已完成"
- NameList.close
- fso.getfile(".\name.ini").delete '删除文件
- set fso = nothing
- '######################################################
- Function Read_WriteINI(INIFilePath,INISection, ININame, INIVlaue)
- Dim fso, strLine, j, strRead
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set IniFile = fso.opentextfile(INIFilePath, 1)
- Do Until IniFile.atendofstream
- strLine = IniFile.readline
- If Trim(strLine) = "[" &INISection & "]" Then
- i="find"
- 'msgbox "找到小节名"
- elseif i="find" and strLine <> "" then '查找Section后的Name,空行loop
- if InStr(strLine, "[")>0 and Trim(strLine) <> "[" &INISection & "]"then
- exit do '下一节点退出
- else
- j=split(strLine,"=")
- if ININame=trim(j(0)) then '查找参数
- strRead = trim(j(1)) '读值
- ' msgbox strRead
- strRpl = strLine
- exit do
- end if
- end if
- end if
- Loop
- IniFile.Close
- Read_WriteINI = strRead
- 'msgbox strRead
- 'if check <> "ReadOnly" then
- Set IniFile = fso.OpenTextFile(INIFilePath, ForReading,true)
- OldAll = IniFile.ReadAll
- IniFile.Close
- NEWALL = Replace(OldAll,strRpl, ININame&"="&INIVlaue)
- Set IniFile = fso.OpenTextFile(INIFilePath, ForWriting)
- IniFile.Write NEWALL
- IniFile.Close
- Set fso = Nothing
- 'end if
- End Function
- Function ShowFileList(folderspec)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set testFile = fso.OpenTextFile(".\name.ini",2,true)
- Dim fso, f, f1, fc, s
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set f = fso.GetFolder(folderspec)
- Set fc = f.Files
- For Each f1 in fc
- s = f1.name
- testFile.writeline folderspec&"\"&s
- x = x &" " &s
- ' Read_WriteINI ".\"&s,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_0","regt ggwerwerrrrrr3"
- Next
- ShowFileList = x
- testFile.close
- set fso = nothing
- End Function