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