gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.9KB

  1. ' Copyright (c) 2012-2020, EnterpriseDB Corporation. All rights reserved
  2. On Error Resume Next
  3. ' PostgreSQL server module load script for Windows
  4. Const ForReading = 1
  5. Const ForWriting = 2
  6. ' Check the command line
  7. If WScript.Arguments.Count <> 5 Then
  8. Wscript.Echo "Usage: loadmodules.vbs <Username> <Password> <Install dir> <Data dir> <Port>"
  9. Wscript.Quit 127
  10. End If
  11. strUsername = WScript.Arguments.Item(0)
  12. strPassword = WScript.Arguments.Item(1)
  13. strInstallDir = WScript.Arguments.Item(2)
  14. strDataDir = WScript.Arguments.Item(3)
  15. iPort = WScript.Arguments.Item(4)
  16. Dim regExp, objShell, objFso, objTempFolder
  17. 'Escape the '%' as '%%', if present in the password
  18. Set regExp = new regexp
  19. regExp.Pattern = "[%]"
  20. strFormattedPassword = regExp.Replace(strPassword, "%%")
  21. iWarn = 0
  22. ' Get a temporary filenames
  23. Set objShell = WScript.CreateObject("WScript.Shell")
  24. Set objFso = CreateObject("Scripting.FileSystemObject")
  25. Set objTempFolder = objFso.GetSpecialFolder(2)
  26. strBatchFile = Replace(objFso.GetTempName, ".tmp", ".bat")
  27. strOutputFile = objTempFolder.Path & "\" & objFso.GetTempName
  28. ' Execute a command. Note that we use Shell.Run here to prevent spawning DOS boxes.
  29. ' Unfortunately that means we have to hack things about to get the command output
  30. Function DoCmd(strCmd)
  31. Dim objBatchFile
  32. Set objBatchFile = objTempFolder.CreateTextFile(strBatchFile, True)
  33. objBatchFile.WriteLine "@ECHO OFF"
  34. objBatchFile.WriteLine "CHCP " & objShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP")
  35. objBatchFile.WriteLine "SET PGPASSWORD=" & strFormattedPassword
  36. objBatchFile.WriteLine strCmd & " > """ & strOutputFile & """ 2>&1"
  37. objBatchFile.WriteLine "SET PGPASSWORD="
  38. objBatchFile.WriteLine "EXIT /B %ERRORLEVEL%"
  39. objBatchFile.Close
  40. WScript.Echo " Executing '" & objTempFolder.Path & "\" & strBatchFile & "'..."
  41. DoCmd = objShell.Run(objTempFolder.Path & "\" & strBatchFile, 0, True)
  42. If objFso.FileExists(objTempFolder.Path & "\" & strBatchFile) = True Then
  43. objFso.DeleteFile objTempFolder.Path & "\" & strBatchFile, True
  44. End If
  45. If objFso.FileExists(strOutputFile) = True Then
  46. Set objOutputFile = objFso.OpenTextFile(strOutputFile, ForReading)
  47. WScript.Echo objOutputFile.ReadAll
  48. objOutputFile.Close
  49. objFso.DeleteFile strOutputFile, True
  50. Else
  51. WScript.Echo " Couldn't find the output file..."
  52. End If
  53. End Function
  54. Sub Warn(msg)
  55. WScript.Echo msg
  56. iWarn = 2
  57. End Sub
  58. ' Install adminpack in the postgres database
  59. WScript.Echo "Installing the adminpack module in the postgres database..."
  60. iRet = DoCmd("""" & strInstallDir & "\bin\psql.exe"" -p " & iPort & " -U " & strUsername & " -c ""CREATE EXTENSION adminpack;"" postgres")
  61. if iRet <> 0 Then warn "Failed to install the 'adminpack' module in the 'postgres' database"
  62. ' All done!!
  63. WScript.Echo "loadmodules.vbs ran to completion"
  64. WScript.Quit iWarn
上海开阖软件有限公司 沪ICP备12045867号-1