1 Attribute VB_Name
= "RunServer"
2 '/*************************************************************************
4 ' * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 ' * Copyright 2008 by Sun Microsystems, Inc.
8 ' * OpenOffice.org - a multi-platform office productivity suite
10 ' * $RCSfile: RunServer.bas,v $
11 ' * $Revision: 1.2.66.2 $
13 ' * This file is part of OpenOffice.org.
15 ' * OpenOffice.org is free software: you can redistribute it and/or modify
16 ' * it under the terms of the GNU Lesser General Public License version 3
17 ' * only, as published by the Free Software Foundation.
19 ' * OpenOffice.org is distributed in the hope that it will be useful,
20 ' * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ' * GNU Lesser General Public License version 3 for more details
23 ' * (a copy is included in the LICENSE file that accompanied this code).
25 ' * You should have received a copy of the GNU Lesser General Public License
26 ' * version 3 along with OpenOffice.org. If not, see
27 ' * <http://www.openoffice.org/license.html>
28 ' * for a copy of the LGPLv3 License.
30 ' ************************************************************************/
34 Private Declare Function WritePrivateProfileString
Lib "kernel32" _
35 Alias "WritePrivateProfileStringA" _
36 (ByVal lpSectionName
As String, _
37 ByVal lpKeyName
As Any
, _
38 ByVal lpString
As Any
, _
39 ByVal lpFileName
As String) As Long
41 Const CWORD_DRIVER
= "_OOoDocAnalysisWordDriver.doc"
42 Const CEXCEL_DRIVER
= "_OOoDocAnalysisExcelDriver.xls"
43 Const CPP_DRIVER
= "_OOoDocAnalysisPPTDriver.ppt"
45 Const CWORD_APP
= "word"
46 Const CEXCEL_APP
= "excel"
49 Const CSTART_FILE
= "PAW_Start_Analysis"
50 Const CSTOP_FILE
= "PAW_Stop_Analysis"
54 Dim serverType
As String
55 serverType
= LCase(Command
$)
56 If (serverType
<> CWORD_APP
) And (serverType
<> CEXCEL_APP
) And (serverType
<> CPP_APP
) Then
57 MsgBox
"Unknown server type: " & serverType
61 Dim fso
As New FileSystemObject
62 Dim driverName
As String
64 If (serverType
= CWORD_APP
) Then
65 driverName
= fso
.GetAbsolutePathName(".\" & CWORD_DRIVER
)
66 ElseIf (serverType
= CEXCEL_APP
) Then
67 driverName
= fso
.GetAbsolutePathName(".\" & CEXCEL_DRIVER
)
68 ElseIf (serverType
= CPP_APP
) Then
69 driverName
= fso
.GetAbsolutePathName(".\" & CPP_DRIVER
)
72 If Not fso
.FileExists(driverName
) Then
73 If (serverType
= CWORD_APP
) Then
74 driverName
= fso
.GetAbsolutePathName(".\Resources\" & CWORD_DRIVER
)
75 ElseIf (serverType
= CEXCEL_APP
) Then
76 driverName
= fso
.GetAbsolutePathName(".\Resources\" & CEXCEL_DRIVER
)
77 ElseIf (serverType
= CPP_APP
) Then
78 driverName
= fso
.GetAbsolutePathName(".\Resources\" & CPP_DRIVER
)
82 If Not fso
.FileExists(driverName
) Then
83 WriteToLog fso
, "ALL", "LaunchDrivers: Could not find: " & driverName
87 If (serverType
= CWORD_APP
) Then
88 OpenWordDriverDoc fso
, driverName
89 ElseIf (serverType
= CEXCEL_APP
) Then
90 OpenExcelDriverDoc fso
, driverName
91 ElseIf (serverType
= CPP_APP
) Then
92 OpenPPDriverDoc fso
, driverName
100 Sub OpenWordDriverDoc(fso
As FileSystemObject
, driverName
As String)
102 Dim wrdApp
As Word
.Application
103 Dim wrdDriverDoc
As Word
.Document
105 On Error GoTo HandleErrors
107 Set wrdApp
= New Word
.Application
108 Set wrdDriverDoc
= wrdApp
.Documents
.Open(driverName
)
110 wrdApp
.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory")
111 If Err
.Number
<> 0 Then
112 WriteToLog fso
, CWORD_APP
, "OpenWordDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
115 wrdDriverDoc
.Close wdDoNotSaveChanges
119 Set wrdDriverDoc
= Nothing
124 WriteToLog fso
, CWORD_APP
, "OpenWordDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
128 Sub OpenExcelDriverDoc(fso
As FileSystemObject
, driverName
As String)
130 Dim excelApp
As Excel
.Application
131 Dim excelDriverDoc
As Excel
.Workbook
133 On Error GoTo HandleErrors
135 Set excelApp
= New Excel
.Application
136 Set excelDriverDoc
= Excel
.Workbooks
.Open(driverName
)
137 excelApp
.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory")
139 If Err
.Number
<> 0 Then
140 WriteToLog fso
, CEXCEL_APP
, "OpenExcelDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
143 excelDriverDoc
.Close
False
147 Set excelDriverDoc
= Nothing
148 Set excelApp
= Nothing
152 WriteToLog fso
, CEXCEL_APP
, "OpenExcelDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
156 Sub OpenPPDriverDoc(fso
As FileSystemObject
, driverName
As String)
158 Dim ppApp
As PowerPoint
.Application
159 Dim ppDriverDoc
As PowerPoint
.Presentation
160 Dim ppDummy(0) As Variant
162 On Error GoTo HandleErrors
164 Set ppApp
= New PowerPoint
.Application
165 ppApp
.Visible
= msoTrue
166 Set ppDriverDoc
= ppApp
.Presentations
.Open(driverName
) ', msoTrue, msoFalse, msoFalse)
167 ppApp
.Run ("AnalysisDriver.AnalyseDirectory")
169 If Err
.Number
<> 0 Then
170 WriteToLog fso
, CPP_APP
, "OpenPPDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
177 Set ppDriverDoc
= Nothing
182 WriteToLog fso
, CPP_APP
, "OpenPPDriverDoc: " & Err
.Number
& " " & Err
.Description
& " " & Err
.Source
186 Sub WriteToLog(fso
As FileSystemObject
, currApp
As String, errMsg
As String)
190 Static ErrCount
As Long
191 Dim logFileName
As String
192 Dim tempPath
As String
194 tempPath
= fso
.GetSpecialFolder(TemporaryFolder
).Path
195 If (tempPath
= "") Then tempPath
= "."
196 logFileName
= fso
.GetAbsolutePathName(tempPath
& "\LauchDrivers.log")
197 ErrCount
= ErrCount
+ 1
199 Call WritePrivateProfileString("ERRORS", currApp
& "_log" & ErrCount
, _