Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

获取OFFICE的安装路径

时 间:2009-02-16 14:06:00
作 者:andymark   ID:1350  城市:深圳
摘 要:获取OFFICE的安装路径
正 文:

Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
   "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
   As Long

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
   ByVal lpReserved As Long, lpType As Long, _
   ByVal lpData As String, lpcbData As Long) As Long
                                                      
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Const REG_SZ As Long = 1
Const KEY_ALL_ACCESS = &H3F
Const HKEY_LOCAL_MACHINE = &H80000002

Public Function OfficePath(OfficeID As String) As String
'用途:获取OFFICE安装路径
'用法:  OfficePath "Access.Aplication"
Dim hKey As Long
Dim RetVal As Long
Dim sProgId As String
Dim sCLSID As String
Dim sPath As String

   sProgId = OfficeID

   RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Classes\" & _
      sProgId & "\CLSID", 0&, KEY_ALL_ACCESS, hKey)
   If RetVal = 0 Then
      Dim n As Long
      RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
      sCLSID = Space(n)
      RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sCLSID, n)
      sCLSID = Left(sCLSID, n - 1)  'drop null-terminator
      RegCloseKey hKey
   End If
   
   
    RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
        "Software\Classes\CLSID\" & sCLSID & "\LocalServer32", 0&, _
      KEY_ALL_ACCESS, hKey)
   If RetVal = 0 Then
      RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
      sPath = Space(n)

      RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sPath, n)
      sPath = Left(sPath, n - 1)
      OfficePath = sPath
    '  MsgBox OfficePath
      RegCloseKey hKey
   End If
End Function


Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助