Advertisement
Guest User

Untitled

a guest
Dec 30th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. Function SelectFolder()
  2. Dim objFolder, objItem, objShell
  3.  
  4. On Error Resume Next
  5. SelectFolder = vbNull
  6.  
  7. Set objShell = CreateObject( "Shell.Application" )
  8. Set objFolder = objShell.BrowseForFolder(0, "Select Config Folder", 0, "")
  9.  
  10. If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
  11.  
  12. Set objFolder = Nothing
  13. Set objshell = Nothing
  14. On Error Goto 0
  15. End Function
  16.  
  17. Dim ConfigDir, Username, Password
  18. ConfigDir = SelectFolder
  19. If ConfigDir = vbNull Then
  20. MsgBox("You didn't selected folder!")
  21. WScript.Quit 0
  22. End If
  23.  
  24. Username = InputBox("Enter your username:")
  25. Password = InputBox("Enter your password:")
  26.  
  27. Dim file, lines, config, line, new_config, auth_file
  28. Set objFSO = CreateObject("Scripting.FileSystemObject")
  29. Set objFolder = objFSO.GetFolder(ConfigDir)
  30. Set lines = CreateObject("System.Collections.ArrayList")
  31. For Each file in objFolder.Files
  32. If objFSO.GetExtensionName(file.Path) = "ovpn" Then
  33. lines.Clear()
  34. Set config = objFSO.OpenTextFile(file.Path)
  35. Do Until config.AtEndOfStream
  36. line = config.ReadLine
  37. If (Trim(line) = "auth-user-pass") Then
  38. lines.Add(Replace(line, "auth-user-pass", "auth-user-pass auth.txt"))
  39. Else
  40. lines.Add(line)
  41. End If
  42. Loop
  43. config.Close
  44. Set new_config = objFSO.CreateTextFile(file, True)
  45. For Each line in lines
  46. new_config.Write line & vbCrLf
  47. Next
  48. new_config.Close
  49. End If
  50. Next
  51.  
  52. Set auth_file = objFSO.CreateTextFile(ConfigDir + "\auth.txt", True)
  53. auth_file.Write Username & vbCrLf
  54. auth_file.Write Password & vbCrLf
  55. auth_file.Close
  56.  
  57. MsgBox("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement