Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

108 řádky
4.3KB

  1. ' Launch the HTA only after the configured MDB passes a real connection check.
  2. Option Explicit
  3. Dim fs, shell, source, settings, desired, current, root, hostPath, dbPath
  4. Dim db, rows, schemaVersion, htaPath, exitCode, checkOnly, childCommand, child, configPath
  5. Set fs = CreateObject("Scripting.FileSystemObject")
  6. Set shell = CreateObject("WScript.Shell")
  7. source = fs.BuildPath(fs.GetParentFolderName(WScript.ScriptFullName), "common.vbs")
  8. ExecuteGlobal fs.OpenTextFile(source, 1).ReadAll
  9. checkOnly = (WScript.Arguments.Count > 0)
  10. configPath = ConfigFilePath()
  11. If checkOnly Then
  12. If LCase(WScript.Arguments(0)) <> "check" Or WScript.Arguments.Count > 2 Then
  13. StopWithError "Usage: launch.vbs [check [config path]]"
  14. End If
  15. If WScript.Arguments.Count = 2 Then configPath = WScript.Arguments(1)
  16. End If
  17. On Error Resume Next
  18. Set settings = LoadConfig(configPath)
  19. If Err.Number <> 0 Then StopWithError "Configuration: " & Err.Description
  20. dbPath = ResolveDbPath(settings)
  21. If Err.Number <> 0 Then StopWithError "Database path: " & Err.Description
  22. On Error GoTo 0
  23. desired = LCase(settings("DB_BITNESS"))
  24. current = HostBitness()
  25. If current <> desired Then
  26. hostPath = TargetHost(desired, current)
  27. If Not fs.FileExists(hostPath) Then StopWithError "Missing " & desired & " script host: " & hostPath
  28. childCommand = Quote(hostPath) & " //nologo " & Quote(WScript.ScriptFullName)
  29. If checkOnly Then childCommand = childCommand & " check " & Quote(configPath)
  30. Set child = shell.Exec(childCommand)
  31. WScript.Echo child.StdOut.ReadAll
  32. If Not child.StdErr.AtEndOfStream Then WScript.Echo child.StdErr.ReadAll
  33. exitCode = child.ExitCode
  34. WScript.Quit exitCode
  35. End If
  36. If Not fs.FileExists(dbPath) Then StopWithError "MDB not found: " & dbPath & _
  37. vbCrLf & "Run tools\init-db.vbs once in the configured " & desired & " host."
  38. On Error Resume Next
  39. Set db = CreateObject("ADODB.Connection")
  40. db.Open "Provider=" & settings("DB_PROVIDER") & ";Data Source=" & dbPath & ";"
  41. If Err.Number <> 0 Then StopWithError "Cannot open MDB with " & settings("DB_PROVIDER") & _
  42. " in " & desired & " host: " & Err.Description
  43. Set rows = db.Execute("SELECT [SchemaVersion] FROM [AppMeta]")
  44. If Err.Number <> 0 Then StopWithError "MDB schema check failed: " & Err.Description
  45. If rows.EOF Then StopWithError "MDB AppMeta is empty"
  46. schemaVersion = CLng(rows.Fields("SchemaVersion").Value)
  47. If Err.Number <> 0 Then StopWithError "Invalid MDB schema version"
  48. If schemaVersion <> 1 Then StopWithError "Unsupported MDB schema version: " & schemaVersion
  49. rows.MoveNext
  50. If Not rows.EOF Then StopWithError "MDB AppMeta has multiple version rows"
  51. rows.Close
  52. db.Close
  53. On Error GoTo 0
  54. root = ProjectRoot()
  55. htaPath = fs.BuildPath(root, "MassMailer.hta")
  56. If Not fs.FileExists(htaPath) Then StopWithError "HTA not found: " & htaPath
  57. hostPath = fs.BuildPath(fs.GetParentFolderName(WScript.FullName), "mshta.exe")
  58. If Not fs.FileExists(hostPath) Then StopWithError "HTA host not found: " & hostPath
  59. WScript.Echo "MDB preflight passed (" & desired & ", schema 1): " & dbPath
  60. If checkOnly Then WScript.Quit 0
  61. shell.Run Quote(hostPath) & " " & Quote(htaPath), 1, False
  62. WScript.Quit 0
  63. Function HostBitness()
  64. Dim processEnv
  65. Set processEnv = shell.Environment("PROCESS")
  66. If InStr(LCase(WScript.FullName), "\syswow64\") > 0 Then
  67. HostBitness = "x86"
  68. ElseIf Len(processEnv("PROCESSOR_ARCHITEW6432")) > 0 Then
  69. HostBitness = "x86"
  70. ElseIf InStr(LCase(processEnv("PROCESSOR_ARCHITECTURE")), "64") > 0 Then
  71. HostBitness = "x64"
  72. Else
  73. HostBitness = "x86"
  74. End If
  75. End Function
  76. Function TargetHost(wanted, actual)
  77. Dim windowsPath
  78. windowsPath = shell.ExpandEnvironmentStrings("%SystemRoot%")
  79. If wanted = "x86" Then
  80. If fs.FolderExists(fs.BuildPath(windowsPath, "SysWOW64")) Then
  81. TargetHost = fs.BuildPath(windowsPath, "SysWOW64\cscript.exe")
  82. Else
  83. TargetHost = fs.BuildPath(windowsPath, "System32\cscript.exe")
  84. End If
  85. ElseIf actual = "x86" Then
  86. TargetHost = fs.BuildPath(windowsPath, "Sysnative\cscript.exe")
  87. Else
  88. TargetHost = fs.BuildPath(windowsPath, "System32\cscript.exe")
  89. End If
  90. End Function
  91. Function Quote(value)
  92. Quote = Chr(34) & value & Chr(34)
  93. End Function
  94. Sub StopWithError(message)
  95. WScript.Echo "ERROR: " & message
  96. WScript.Quit 1
  97. End Sub

Powered by TurnKey Linux.