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.

81 line
2.9KB

  1. ' Copyright (c) 2012-2020, EnterpriseDB Corporation. All rights reserved
  2. On Error Resume Next
  3. ' PostgreSQL server startup configuration script for Windows
  4. ' Check the command line
  5. If WScript.Arguments.Count <> 6 Then
  6. Wscript.Echo "Usage: startupcfg.vbs <Major.Minor version> <Username> <Password> <Install dir> <Data dir> <ServerName>"
  7. Wscript.Quit 127
  8. End If
  9. strVersion = WScript.Arguments.Item(0)
  10. strUsername = WScript.Arguments.Item(1)
  11. strPassword = WScript.Arguments.Item(2)
  12. strInstallDir = WScript.Arguments.Item(3)
  13. strDataDir = WScript.Arguments.Item(4)
  14. strServiceName = WScript.Arguments.Item(5)
  15. Dim regExp, objShell, objFso, objTempFolder
  16. 'Escape the '%' as '%%', if present in the password
  17. Set regExp = new regexp
  18. regExp.Pattern = "[%]"
  19. strFormattedPassword = regExp.Replace(strPassword, "%%")
  20. iWarn = 0
  21. ' Get temporary filenames
  22. Set objShell = WScript.CreateObject("WScript.Shell")
  23. Set objFso = CreateObject("Scripting.FileSystemObject")
  24. Set objTempFolder = objFso.GetSpecialFolder(2)
  25. strBatchFile = Replace(objFso.GetTempName, ".tmp", ".bat")
  26. strOutputFile = objTempFolder.Path & "\" & objFso.GetTempName
  27. ' Execute a command
  28. Function DoCmd(strCmd)
  29. Dim objBatchFile
  30. Set objBatchFile = objTempFolder.CreateTextFile(strBatchFile, True)
  31. objBatchFile.WriteLine "@ECHO OFF"
  32. objBatchFile.WriteLine "CHCP " & objShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP")
  33. objBatchFile.WriteLine strCmd & " > """ & strOutputFile & """ 2>&1"
  34. objBatchFile.WriteLine "EXIT /B %ERRORLEVEL%"
  35. objBatchFile.Close
  36. DoCmd = objShell.Run(objTempFolder.Path & "\" & strBatchFile, 0, True)
  37. If objFso.FileExists(objTempFolder.Path & "\" & strBatchFile) = True Then
  38. objFso.DeleteFile objTempFolder.Path & "\" & strBatchFile, True
  39. End If
  40. If objFso.FileExists(strOutputFile) = True Then
  41. Set objOutputFile = objFso.OpenTextFile(strOutputFile, ForReading)
  42. WScript.Echo objOutputFile.ReadAll
  43. objOutputFile.Close
  44. objFso.DeleteFile strOutputFile, True
  45. End If
  46. End Function
  47. Sub Die(msg)
  48. WScript.Echo msg
  49. WScript.Quit 1
  50. End Sub
  51. Sub Warn(msg)
  52. WScript.Echo msg
  53. iWarn = 2
  54. End Sub
  55. ' We'll let pg_ctl do all the heavy lifting
  56. If strUsername = "NT AUTHORITY\NetworkService" Then
  57. iRet = DoCmd("""" & strInstallDir & "\bin\pg_ctl.exe"" register -N """ & strServiceName & """ -U """ & strUsername & """ -D """ & strDataDir & """ -w")
  58. Else
  59. iRet = DoCmd("""" & strInstallDir & "\bin\pg_ctl.exe"" register -N """ & strServiceName & """ -U """ & strUsername & """ -P """ & strFormattedPassword & """ -D """ & strDataDir & """ -w")
  60. End If
  61. if iRet <> 0 Then
  62. Die "Failed to register the service with the service control manager"
  63. End If
  64. ' Write the DisplayName manually
  65. objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\" & strServiceName & "\DisplayName", strServiceName & " - PostgreSQL Server " & strVersion, "REG_SZ"
  66. WScript.Echo "startupcfg.vbs ran to completion"
  67. WScript.Quit 0
上海开阖软件有限公司 沪ICP备12045867号-1