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