批量修改Xshell登陸文件.vbs

CRT可以在Session下修改Properties,從而批量修改配置文件

  1. '2012年12月29日19:06:59 用於修改Xshell登陸文件  
  2. On Error Resume Next 
  3. Const ForReading = 1  
  4. Const ForWriting = 2  
  5. Const Forappending = 8  
  6. Dim check  
  7. 'check = "ReadOnly"  
  8. GETINFO =  inputbox("請輸入”passwd,enablepasswd” :" & vbcrlf & _  
  9.                 "此腳本請在登陸文件所在目錄運行" & vbcrlf & _  
  10.                 "登錄名默認admin,如有改變請自行修改腳本" ,_  
  11.                 month(NOW) &"月" & day(NOW)& "日"&" "&"修改自動登陸文件" ,_  
  12.                 "y7Gw$ka6*,(UhFg2g!X")   
  13. ArryPwd = split(GETINFO ,",")  
  14. passwd = ArryPwd(0)  
  15. enablepasswd = ArryPwd(1)  
  16. Set fso = CreateObject("Scripting.FileSystemObject")  
  17. path = fso.GetFile(Wscript.ScriptFullName).ParentFolder  
  18. 'msgbox ShowFileList(path)  
  19.  ShowFileList(path)  
  20. Set NameList = fso.OpenTextFile(".\name.ini")  
  21.  
  22. DO While NameList.AtEndOfStream <> True 
  23.     INIFileName = NameList.ReadLine  
  24.     if  INIFileName <>"" then  
  25. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_0",":" 
  26. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_0","admin" 
  27. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_1",":" 
  28. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_1",passwd  
  29. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_2",">" 
  30. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_2","enable" 
  31. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_3",":" 
  32. Read_WriteINI INIFileName ,"CONNECTION:AUTHENTICATION","ExpectSend_Send_3",enablepasswd  
  33. end if  
  34. loop  
  35. msgbox "已完成" 
  36. NameList.close  
  37. fso.getfile(".\name.ini").delete    '刪除文件  
  38. set fso = nothing   
  39. '######################################################  
  40. Function Read_WriteINI(INIFilePath,INISection, ININame, INIVlaue)  
  41. Dim fso, strLine, j, strRead  
  42. Set fso = CreateObject("Scripting.FileSystemObject")  
  43. Set IniFile = fso.opentextfile(INIFilePath, 1)  
  44. Do Until IniFile.atendofstream  
  45.     strLine = IniFile.readline  
  46.     If  Trim(strLine) = "[" &INISection & "]" Then   
  47.       i="find" 
  48.     'msgbox "找到小節名"  
  49.     elseif i="find" and strLine <> "" then   '查找Section後的Name,空行loop  
  50.      if  InStr(strLine, "[")>0 and Trim(strLine) <> "[" &INISection & "]"then   
  51.      exit do              '下一節點退出  
  52.      else   
  53.         j=split(strLine,"=")          
  54.         if  ININame=trim(j(0)) then   '查找參數  
  55.             strRead = trim(j(1))        '讀值  
  56. '           msgbox strRead  
  57.             strRpl = strLine  
  58.             exit do   
  59.         end if   
  60.      end if   
  61.     end if  
  62. Loop 
  63. IniFile.Close  
  64. Read_WriteINI = strRead  
  65. 'msgbox strRead  
  66. 'if check <> "ReadOnly" then   
  67. Set IniFile = fso.OpenTextFile(INIFilePath, ForReading,true)  
  68. OldAll = IniFile.ReadAll  
  69. IniFile.Close  
  70. NEWALL = Replace(OldAll,strRpl, ININame&"="&INIVlaue)  
  71. Set IniFile = fso.OpenTextFile(INIFilePath, ForWriting)  
  72. IniFile.Write NEWALL  
  73. IniFile.Close  
  74. Set fso = Nothing 
  75. 'end if   
  76. End Function 
  77.  
  78. Function ShowFileList(folderspec)     
  79. Set fso = CreateObject("Scripting.FileSystemObject")  
  80. Set testFile = fso.OpenTextFile(".\name.ini",2,true)   
  81. Dim fso, f, f1, fc, s  
  82.     Set fso = CreateObject("Scripting.FileSystemObject")  
  83.     Set f = fso.GetFolder(folderspec)  
  84.         Set fc = f.Files  
  85.             For Each f1 in fc  
  86.         s =  f1.name  
  87. testFile.writeline  folderspec&"\"&s  
  88.          x = x &" " &s  
  89. '  Read_WriteINI ".\"&s,"CONNECTION:AUTHENTICATION","ExpectSend_Expect_0","regt ggwerwerrrrrr3"  
  90.    Next 
  91.  ShowFileList = x  
  92.  testFile.close  
  93. set fso = nothing   
  94. End Function 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章