1Attribute VB_Name = "RunServer" 2'/************************************************************************* 3' * 4' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5' 6' Copyright 2000, 2010 Oracle and/or its affiliates. 7' 8' OpenOffice.org - a multi-platform office productivity suite 9' 10' This file is part of OpenOffice.org. 11' 12' OpenOffice.org is free software: you can redistribute it and/or modify 13' it under the terms of the GNU Lesser General Public License version 3 14' only, as published by the Free Software Foundation. 15' 16' OpenOffice.org is distributed in the hope that it will be useful, 17' but WITHOUT ANY WARRANTY; without even the implied warranty of 18' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19' GNU Lesser General Public License version 3 for more details 20' (a copy is included in the LICENSE file that accompanied this code). 21' 22' You should have received a copy of the GNU Lesser General Public License 23' version 3 along with OpenOffice.org. If not, see 24' <http://www.openoffice.org/license.html> 25' for a copy of the LGPLv3 License. 26' 27' ************************************************************************/ 28 29Option Explicit 30 31Private Declare Function WritePrivateProfileString Lib "kernel32" _ 32 Alias "WritePrivateProfileStringA" _ 33 (ByVal lpSectionName As String, _ 34 ByVal lpKeyName As Any, _ 35 ByVal lpString As Any, _ 36 ByVal lpFileName As String) As Long 37 38Const CWORD_DRIVER = "_OOoDocAnalysisWordDriver.doc" 39Const CEXCEL_DRIVER = "_OOoDocAnalysisExcelDriver.xls" 40Const CPP_DRIVER = "_OOoDocAnalysisPPTDriver.ppt" 41 42Const CWORD_APP = "word" 43Const CEXCEL_APP = "excel" 44Const CPP_APP = "pp" 45 46Const CSTART_FILE = "PAW_Start_Analysis" 47Const CSTOP_FILE = "PAW_Stop_Analysis" 48 49Sub Main() 50 51 Dim serverType As String 52 serverType = LCase(Command$) 53 If (serverType <> CWORD_APP) And (serverType <> CEXCEL_APP) And (serverType <> CPP_APP) Then 54 MsgBox "Unknown server type: " & serverType 55 GoTo FinalExit 56 End If 57 58 Dim fso As New FileSystemObject 59 Dim driverName As String 60 61 If (serverType = CWORD_APP) Then 62 driverName = fso.GetAbsolutePathName(".\" & CWORD_DRIVER) 63 ElseIf (serverType = CEXCEL_APP) Then 64 driverName = fso.GetAbsolutePathName(".\" & CEXCEL_DRIVER) 65 ElseIf (serverType = CPP_APP) Then 66 driverName = fso.GetAbsolutePathName(".\" & CPP_DRIVER) 67 End If 68 69 If Not fso.FileExists(driverName) Then 70 If (serverType = CWORD_APP) Then 71 driverName = fso.GetAbsolutePathName(".\Resources\" & CWORD_DRIVER) 72 ElseIf (serverType = CEXCEL_APP) Then 73 driverName = fso.GetAbsolutePathName(".\Resources\" & CEXCEL_DRIVER) 74 ElseIf (serverType = CPP_APP) Then 75 driverName = fso.GetAbsolutePathName(".\Resources\" & CPP_DRIVER) 76 End If 77 End If 78 79 If Not fso.FileExists(driverName) Then 80 WriteToLog fso, "ALL", "LaunchDrivers: Could not find: " & driverName 81 GoTo FinalExit 82 End If 83 84 If (serverType = CWORD_APP) Then 85 OpenWordDriverDoc fso, driverName 86 ElseIf (serverType = CEXCEL_APP) Then 87 OpenExcelDriverDoc fso, driverName 88 ElseIf (serverType = CPP_APP) Then 89 OpenPPDriverDoc fso, driverName 90 End If 91 92FinalExit: 93 94 Set fso = Nothing 95End Sub 96 97Sub OpenWordDriverDoc(fso As FileSystemObject, driverName As String) 98 99 Dim wrdApp As Word.Application 100 Dim wrdDriverDoc As Word.Document 101 102 On Error GoTo HandleErrors 103 104 Set wrdApp = New Word.Application 105 Set wrdDriverDoc = wrdApp.Documents.Open(driverName) 106 107 wrdApp.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory") 108 If Err.Number <> 0 Then 109 WriteToLog fso, CWORD_APP, "OpenWordDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 110 End If 111 112 wrdDriverDoc.Close wdDoNotSaveChanges 113 wrdApp.Quit False 114 115FinalExit: 116 Set wrdDriverDoc = Nothing 117 Set wrdApp = Nothing 118 Exit Sub 119 120HandleErrors: 121 WriteToLog fso, CWORD_APP, "OpenWordDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 122 Resume FinalExit 123End Sub 124 125Sub OpenExcelDriverDoc(fso As FileSystemObject, driverName As String) 126 127 Dim excelApp As Excel.Application 128 Dim excelDriverDoc As Excel.Workbook 129 130 On Error GoTo HandleErrors 131 132 Set excelApp = New Excel.Application 133 Set excelDriverDoc = Excel.Workbooks.Open(driverName) 134 excelApp.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory") 135 136 If Err.Number <> 0 Then 137 WriteToLog fso, CEXCEL_APP, "OpenExcelDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 138 End If 139 140 excelDriverDoc.Close False 141 excelApp.Quit 142 143FinalExit: 144 Set excelDriverDoc = Nothing 145 Set excelApp = Nothing 146 Exit Sub 147 148HandleErrors: 149 WriteToLog fso, CEXCEL_APP, "OpenExcelDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 150 Resume FinalExit 151End Sub 152 153Sub OpenPPDriverDoc(fso As FileSystemObject, driverName As String) 154 155 Dim ppApp As PowerPoint.Application 156 Dim ppDriverDoc As PowerPoint.Presentation 157 Dim ppDummy(0) As Variant 158 159 On Error GoTo HandleErrors 160 161 Set ppApp = New PowerPoint.Application 162 ppApp.Visible = msoTrue 163 Set ppDriverDoc = ppApp.Presentations.Open(driverName) ', msoTrue, msoFalse, msoFalse) 164 ppApp.Run ("AnalysisDriver.AnalyseDirectory") 165 166 If Err.Number <> 0 Then 167 WriteToLog fso, CPP_APP, "OpenPPDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 168 End If 169 170 ppDriverDoc.Close 171 ppApp.Quit 172 173FinalExit: 174 Set ppDriverDoc = Nothing 175 Set ppApp = Nothing 176 Exit Sub 177 178HandleErrors: 179 WriteToLog fso, CPP_APP, "OpenPPDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source 180 Resume FinalExit 181End Sub 182 183Sub WriteToLog(fso As FileSystemObject, currApp As String, errMsg As String) 184 185 On Error Resume Next 186 187 Static ErrCount As Long 188 Dim logFileName As String 189 Dim tempPath As String 190 191 tempPath = fso.GetSpecialFolder(TemporaryFolder).Path 192 If (tempPath = "") Then tempPath = "." 193 logFileName = fso.GetAbsolutePathName(tempPath & "\LauchDrivers.log") 194 ErrCount = ErrCount + 1 195 196 Call WritePrivateProfileString("ERRORS", currApp & "_log" & ErrCount, _ 197 errMsg, logFileName) 198End Sub 199 200