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