1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?> 2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*b1cdbd2cSJim Jagielski<!--*********************************************************** 4*b1cdbd2cSJim Jagielski * 5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 6*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 7*b1cdbd2cSJim Jagielski * distributed with this work for additional information 8*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 11*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 14*b1cdbd2cSJim Jagielski * 15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 20*b1cdbd2cSJim Jagielski * under the License. 21*b1cdbd2cSJim Jagielski * 22*b1cdbd2cSJim Jagielski ***********************************************************--> 23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="API" script:language="StarBasic">Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _ 24*b1cdbd2cSJim Jagielski (ByVal hKey As Long, _ 25*b1cdbd2cSJim Jagielski ByVal lpSubKey As String, _ 26*b1cdbd2cSJim Jagielski ByVal ulOptions As Long, _ 27*b1cdbd2cSJim Jagielski ByVal samDesired As Long, _ 28*b1cdbd2cSJim Jagielski phkResult As Long) As Long 29*b1cdbd2cSJim Jagielski 30*b1cdbd2cSJim JagielskiDeclare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" _ 31*b1cdbd2cSJim Jagielski (ByVal hKey As Long, _ 32*b1cdbd2cSJim Jagielski ByVal lpValueName As String, _ 33*b1cdbd2cSJim Jagielski ByVal lpReserved As Long, _ 34*b1cdbd2cSJim Jagielski lpType As Long, _ 35*b1cdbd2cSJim Jagielski lpData As String, _ 36*b1cdbd2cSJim Jagielski lpcbData As Long) As Long 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim JagielskiDeclare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" _ 39*b1cdbd2cSJim Jagielski (ByVal hKey As Long, _ 40*b1cdbd2cSJim Jagielski ByVal lpValueName As String, _ 41*b1cdbd2cSJim Jagielski ByVal lpReserved As Long, _ 42*b1cdbd2cSJim Jagielski lpType As Long, _ 43*b1cdbd2cSJim Jagielski lpData As Long, _ 44*b1cdbd2cSJim Jagielski lpcbData As Long) As Long 45*b1cdbd2cSJim Jagielski 46*b1cdbd2cSJim JagielskiDeclare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" _ 47*b1cdbd2cSJim Jagielski (ByVal hKey As Long, _ 48*b1cdbd2cSJim Jagielski ByVal lpValueName As String, _ 49*b1cdbd2cSJim Jagielski ByVal lpReserved As Long, _ 50*b1cdbd2cSJim Jagielski lpType As Long, _ 51*b1cdbd2cSJim Jagielski ByVal lpData As Long, _ 52*b1cdbd2cSJim Jagielski lpcbData As Long) As Long 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim JagielskiDeclare Function RegCloseKeyA Lib "advapi32.dll" Alias "RegCloseKey" _ 55*b1cdbd2cSJim Jagielski (ByVal hKey As Long) As Long 56*b1cdbd2cSJim Jagielski 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim JagielskiPublic Const HKEY_CLASSES_ROOT = &H80000000 59*b1cdbd2cSJim JagielskiPublic Const HKEY_CURRENT_USER = &H80000001 60*b1cdbd2cSJim JagielskiPublic Const HKEY_LOCAL_MACHINE = &H80000002 61*b1cdbd2cSJim JagielskiPublic Const HKEY_USERS = &H80000003 62*b1cdbd2cSJim JagielskiPublic Const KEY_ALL_ACCESS = &H3F 63*b1cdbd2cSJim JagielskiPublic Const REG_OPTION_NON_VOLATILE = 0 64*b1cdbd2cSJim JagielskiPublic Const REG_SZ As Long = 1 65*b1cdbd2cSJim JagielskiPublic Const REG_DWORD As Long = 4 66*b1cdbd2cSJim JagielskiPublic Const ERROR_NONE = 0 67*b1cdbd2cSJim JagielskiPublic Const ERROR_BADDB = 1 68*b1cdbd2cSJim JagielskiPublic Const ERROR_BADKEY = 2 69*b1cdbd2cSJim JagielskiPublic Const ERROR_CANTOPEN = 3 70*b1cdbd2cSJim JagielskiPublic Const ERROR_CANTREAD = 4 71*b1cdbd2cSJim JagielskiPublic Const ERROR_CANTWRITE = 5 72*b1cdbd2cSJim JagielskiPublic Const ERROR_OUTOFMEMORY = 6 73*b1cdbd2cSJim JagielskiPublic Const ERROR_INVALID_PARAMETER = 7 74*b1cdbd2cSJim JagielskiPublic Const ERROR_ACCESS_DENIED = 8 75*b1cdbd2cSJim JagielskiPublic Const ERROR_INVALID_PARAMETERS = 87 76*b1cdbd2cSJim JagielskiPublic Const ERROR_NO_MORE_ITEMS = 259 77*b1cdbd2cSJim Jagielski'Public Const KEY_READ = &H20019 78*b1cdbd2cSJim Jagielski 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim JagielskiFunction OpenRegKey(lBaseKey As Long, sKeyName As String) As Variant 81*b1cdbd2cSJim JagielskiDim LocKeyValue 82*b1cdbd2cSJim JagielskiDim hKey as Long 83*b1cdbd2cSJim JagielskiDim lRetValue as Long 84*b1cdbd2cSJim Jagielski lRetValue = RegOpenKeyEx(lBaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey) 85*b1cdbd2cSJim Jagielski' lRetValue = QueryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Outlook Express\5.0\Default Settings", "Revocation Checking") 86*b1cdbd2cSJim Jagielski If hKey <> 0 Then 87*b1cdbd2cSJim Jagielski RegCloseKeyA (hKey) 88*b1cdbd2cSJim Jagielski End If 89*b1cdbd2cSJim Jagielski OpenRegKey() = lRetValue 90*b1cdbd2cSJim JagielskiEnd Function 91*b1cdbd2cSJim Jagielski 92*b1cdbd2cSJim Jagielski 93*b1cdbd2cSJim JagielskiFunction GetDefaultPath(CurOffice as Integer) As String 94*b1cdbd2cSJim JagielskiDim sPath as String 95*b1cdbd2cSJim JagielskiDim Index as Integer 96*b1cdbd2cSJim Jagielski Select Case Wizardmode 97*b1cdbd2cSJim Jagielski Case SBMICROSOFTMODE 98*b1cdbd2cSJim Jagielski Index = Applications(CurOffice,SBAPPLKEY) 99*b1cdbd2cSJim Jagielski If GetGUIType = 1 Then ' Windows 100*b1cdbd2cSJim Jagielski sPath = QueryValue(HKEY_LOCAL_MACHINE, sKeyName(Index), sValueName(Index)) 101*b1cdbd2cSJim Jagielski Else 102*b1cdbd2cSJim Jagielski sPath = "" 103*b1cdbd2cSJim Jagielski End If 104*b1cdbd2cSJim Jagielski If sPath = "" Then 105*b1cdbd2cSJim Jagielski sPath = SOWorkPath 106*b1cdbd2cSJim Jagielski End If 107*b1cdbd2cSJim Jagielski GetDefaultPath = sPath 108*b1cdbd2cSJim Jagielski Case SBXMLMODE 109*b1cdbd2cSJim Jagielski GetDefaultPath = SOWorkPath 110*b1cdbd2cSJim Jagielski End Select 111*b1cdbd2cSJim JagielskiEnd Function 112*b1cdbd2cSJim Jagielski 113*b1cdbd2cSJim Jagielski 114*b1cdbd2cSJim JagielskiFunction GetTemplateDefaultPath(Index as Integer) As String 115*b1cdbd2cSJim JagielskiDim sLocTemplatePath as String 116*b1cdbd2cSJim JagielskiDim sLocProgrampath as String 117*b1cdbd2cSJim JagielskiDim Progstring as String 118*b1cdbd2cSJim JagielskiDim PathList()as String 119*b1cdbd2cSJim JagielskiDim Maxindex as Integer 120*b1cdbd2cSJim JagielskiDim OldsLocTemplatePath 121*b1cdbd2cSJim JagielskiDim sTemplateKeyName as String 122*b1cdbd2cSJim JagielskiDim sTemplateValueName as String 123*b1cdbd2cSJim Jagielski On Local Error Goto NOVAlIDSYSTEMPATH 124*b1cdbd2cSJim Jagielski Select Case WizardMode 125*b1cdbd2cSJim Jagielski Case SBMICROSOFTMODE 126*b1cdbd2cSJim Jagielski If GetGUIType = 1 Then ' Windows 127*b1cdbd2cSJim Jagielski ' Template directory of Office 97 128*b1cdbd2cSJim Jagielski sTemplateKeyName = "Software\Microsoft\Office\8.0\Common\FileNew\LocalTemplates" 129*b1cdbd2cSJim Jagielski sTemplateValueName = "" 130*b1cdbd2cSJim Jagielski sLocTemplatePath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName) 131*b1cdbd2cSJim Jagielski 132*b1cdbd2cSJim Jagielski If sLocTemplatePath = "" Then 133*b1cdbd2cSJim Jagielski ' Retrieve the template directory of Office 2000 134*b1cdbd2cSJim Jagielski ' Unfortunately there is no existing note about the template directory in 135*b1cdbd2cSJim Jagielski ' the whole registry. 136*b1cdbd2cSJim Jagielski 137*b1cdbd2cSJim Jagielski ' Programdirectory of Office 2000 138*b1cdbd2cSJim Jagielski sTemplateKeyName = "Software\Microsoft\Office\9.0\Common\InstallRoot" 139*b1cdbd2cSJim Jagielski sTemplateValueName = "Path" 140*b1cdbd2cSJim Jagielski sLocProgrampath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName) 141*b1cdbd2cSJim Jagielski If sLocProgrampath <> "" Then 142*b1cdbd2cSJim Jagielski If Right(sLocProgrampath, 1) <> "\" Then 143*b1cdbd2cSJim Jagielski sLocProgrampath = sLocProgrampath & "\" 144*b1cdbd2cSJim Jagielski End If 145*b1cdbd2cSJim Jagielski PathList() = ArrayoutofString(sLocProgrampath,"\",Maxindex) 146*b1cdbd2cSJim Jagielski Progstring = "\" & PathList(Maxindex-1) & "\" 147*b1cdbd2cSJim Jagielski OldsLocTemplatePath = DeleteStr(sLocProgramPath,Progstring) 148*b1cdbd2cSJim Jagielski 149*b1cdbd2cSJim Jagielski sLocTemplatePath = OldsLocTemplatePath & "\" & "Templates" 150*b1cdbd2cSJim Jagielski 151*b1cdbd2cSJim Jagielski ' Does this subdirectory "templates" exist at all 152*b1cdbd2cSJim Jagielski If oUcb.Exists(sLocTemplatePath) Then 153*b1cdbd2cSJim Jagielski ' If Not the main directory of the office is the base 154*b1cdbd2cSJim Jagielski sLocTemplatePath = OldsLocTemplatePath 155*b1cdbd2cSJim Jagielski End If 156*b1cdbd2cSJim Jagielski Else 157*b1cdbd2cSJim Jagielski sLocTemplatePath = SOWorkPath 158*b1cdbd2cSJim Jagielski End If 159*b1cdbd2cSJim Jagielski End If 160*b1cdbd2cSJim Jagielski GetTemplateDefaultPath = ConvertToUrl(sLocTemplatePath) 161*b1cdbd2cSJim Jagielski Else 162*b1cdbd2cSJim Jagielski GetTemplateDefaultPath = SOWorkPath 163*b1cdbd2cSJim Jagielski End If 164*b1cdbd2cSJim Jagielski Case SBXMLMODE 165*b1cdbd2cSJim Jagielski If Index = 3 Then 166*b1cdbd2cSJim Jagielski ' Helper Application with no templates 167*b1cdbd2cSJim Jagielski GetTemplateDefaultPath = SOWorkPath 168*b1cdbd2cSJim Jagielski Else 169*b1cdbd2cSJim Jagielski GetTemplateDefaultPath = SOTemplatePath 170*b1cdbd2cSJim Jagielski End If 171*b1cdbd2cSJim Jagielski End Select 172*b1cdbd2cSJim JagielskiNOVALIDSYSTEMPATH: 173*b1cdbd2cSJim Jagielski If Err <> 0 Then 174*b1cdbd2cSJim Jagielski GetTemplateDefaultPath() = SOWorkPath 175*b1cdbd2cSJim Jagielski Resume ONITGOES 176*b1cdbd2cSJim Jagielski ONITGOES: 177*b1cdbd2cSJim Jagielski End If 178*b1cdbd2cSJim JagielskiEnd Function 179*b1cdbd2cSJim Jagielski 180*b1cdbd2cSJim Jagielski 181*b1cdbd2cSJim JagielskiFunction QueryValueEx(ByVal lhKey, ByVal szValueName As String, vValue As String) As Long 182*b1cdbd2cSJim JagielskiDim cch As Long 183*b1cdbd2cSJim JagielskiDim lrc As Long 184*b1cdbd2cSJim JagielskiDim lType As Long 185*b1cdbd2cSJim JagielskiDim lValue As Long 186*b1cdbd2cSJim JagielskiDim sValue As String 187*b1cdbd2cSJim JagielskiDim Empty 188*b1cdbd2cSJim Jagielski 189*b1cdbd2cSJim Jagielski On Error GoTo QueryValueExError 190*b1cdbd2cSJim Jagielski 191*b1cdbd2cSJim Jagielski lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch) 192*b1cdbd2cSJim Jagielski If lrc <> ERROR_NONE Then Error 5 193*b1cdbd2cSJim Jagielski Select Case lType 194*b1cdbd2cSJim Jagielski Case REG_SZ: 195*b1cdbd2cSJim Jagielski sValue = String(cch, 0) 196*b1cdbd2cSJim Jagielski lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch) 197*b1cdbd2cSJim Jagielski If lrc = ERROR_NONE Then 198*b1cdbd2cSJim Jagielski vValue = Left$(sValue, cch) 199*b1cdbd2cSJim Jagielski Else 200*b1cdbd2cSJim Jagielski vValue = Empty 201*b1cdbd2cSJim Jagielski End If 202*b1cdbd2cSJim Jagielski Case REG_DWORD: 203*b1cdbd2cSJim Jagielski lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch) 204*b1cdbd2cSJim Jagielski If lrc = ERROR_NONE Then 205*b1cdbd2cSJim Jagielski vValue = lValue 206*b1cdbd2cSJim Jagielski End If 207*b1cdbd2cSJim Jagielski Case Else 208*b1cdbd2cSJim Jagielski lrc = -1 209*b1cdbd2cSJim Jagielski End Select 210*b1cdbd2cSJim JagielskiQueryValueExExit: 211*b1cdbd2cSJim Jagielski QueryValueEx = lrc 212*b1cdbd2cSJim Jagielski Exit Function 213*b1cdbd2cSJim JagielskiQueryValueExError: 214*b1cdbd2cSJim Jagielski Resume QueryValueExExit 215*b1cdbd2cSJim JagielskiEnd Function 216*b1cdbd2cSJim Jagielski 217*b1cdbd2cSJim Jagielski 218*b1cdbd2cSJim JagielskiFunction QueryValue(BaseKey As Long, sKeyName As String, sValueName As String) As Variant 219*b1cdbd2cSJim JagielskiDim lRetVal As Long ' Returnvalue API-Call 220*b1cdbd2cSJim JagielskiDim hKey As Long ' Onen key handle 221*b1cdbd2cSJim JagielskiDim vValue As String ' Key value 222*b1cdbd2cSJim Jagielski 223*b1cdbd2cSJim Jagielski lRetVal = RegOpenKeyEx(BaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey) 224*b1cdbd2cSJim Jagielski lRetVal = QueryValueEx(hKey, sValueName, vValue) 225*b1cdbd2cSJim Jagielski RegCloseKeyA (hKey) 226*b1cdbd2cSJim Jagielski QueryValue = vValue 227*b1cdbd2cSJim JagielskiEnd Function 228*b1cdbd2cSJim Jagielski</script:module> 229