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