1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
Option Compare Database
Option Explicit
Const TRUSTED_LOCATION As String = "Software\Microsoft\Office\14.0\Access\Security\Trusted Locations"
Const ERROR_NO_MORE_ITEMS As Long = 259&
Const HKEY_CURRENT_USER As Long = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Function GetLocations(ByRef MyFreeLocation As String) As Boolean
Const LOCATION As String = "Location"
Const BUFFER_SIZE As Long = 255
Dim lngHKey As Long
Dim I As Long
Dim strDataName As String
Dim strData As String
Dim lngRet As Long
Dim lngRetData As Long
Dim intLocationIndex As Integer
lngRet = BUFFER_SIZE
If RegOpenKey(HKEY_CURRENT_USER, TRUSTED_LOCATION, lngHKey) = 0 Then
strDataName = Space(BUFFER_SIZE)
While RegEnumKeyEx(lngHKey, I, strDataName, lngRet, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
intLocationIndex = CInt(Mid$(Left$(strDataName, lngRet), Len(LOCATION) + 1))
I = I + 1
strDataName = Space(BUFFER_SIZE): lngRet = BUFFER_SIZE
Wend
RegCloseKey lngHKey
intLocationIndex = intLocationIndex + 1
GetLocations = True
Else
intLocationIndex = 0
GetLocations = False
End If
MyFreeLocation = LOCATION & intLocationIndex
End Function |
Partager