设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2149|回复: 0
打印 上一主题 下一主题

高手!2007和2003的路径取得缘何有异?

[复制链接]
跳转到指定楼层
1#
发表于 2008-2-10 17:15:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在2003中,可以用这个方式取得msaccess.exe路径,然而,2007不行,虽然在注册表中 只是11.0和12.0的差别。
据说,和2007的安全设置有关,请高手分析一下原因!或者另辟蹊径。不要说syscmd了,这个方式不够灵活

Function AccWya() As String
Dim P As Integer, DesAcex As String
    DesAcex = PathReg("11.0\Access\InstallRoot", "Path") 'Common
    DesAcex = Trim(DesAcex)
    P = InStr(DesAcex, "OFFICE11\")
    If P > 0 Then DesAcex = Left(DesAcex, P - 1) & "OFFICE11\"
    'If Right(DesAcex, 1) <> "\" Then DesAcex = DesAcex & "\"
    'DesAcex = UCase(DesAcex)
    'DesAcex = DesAcex & "MSACCESS.EXE "
'DesAcex = "C:\Program Files\Microsoft Office\OFFICE12\MSACCESS.EXE "
'DesAcex = ""
If dir(DesAcex) = "" Then '12.0 Access InstallRoot Path.txt
    DesAcex = PathReg("12.0\Access\InstallRoot", "Path")
    DesAcex = Trim(DesAcex)
    'DesAcex = CStr(DesAcex)
    P = InStr(DesAcex, "OFFICE12\")
    If P > 0 Then DesAcex = Left(DesAcex, P - 1) & "OFFICE12\"
   
    'DesAcex = DesAcex + "MSACCESS.EXE "
End If
'MsgBox DesAcex
If Right(DesAcex, 1) <> "\" Then DesAcex = DesAcex & "\"
DesAcex = UCase(DesAcex)
AccWya = DesAcex
'MsgBox AccWya
AccWya = AccWya & "MSACCESS.EXE "
'MsgBox AccWya
End Function


Function PathReg(VersionP, PathKey)
1001 Dim phkResult As Long, SA As SECURITY_ATTRIBUTES
1002 Dim lResult As Long, Index As Long, dwReserved As Long, szBuffer As String, _
           lBuffSize As Long, szBuffer2 As String, lBuffSize2 As Long, lType As Long, FT As FILETIME
1003  hKey = HKEY_LOCAL_MACHINE '设定主Key
1004  SubKey = "Software\Microsoft\office\" & VersionP & "\" '设定子Key
1005  lResult = RegOpenKeyEx(hKey, SubKey, 0, 1, phkResult)  '开启
1006  Index = 0
1007  dwReserved = 0
1008  Do While lResult = ERROR_SUCCESS
1009        szBuffer = Space(255)
1010        lBuffSize = Len(szBuffer)
1011        szBuffer2 = Space(255)
1012        lBuffSize2 = Len(szBuffer2)
1013        lResult = RegEnumValue(phkResult, Index, szBuffer, lBuffSize, _
                             dwReserved, lType, szBuffer2, lBuffSize2)
1014        If Left(szBuffer, lBuffSize) = PathKey Then  '找到了
1015            PathReg = Left(szBuffer2, lBuffSize2)  '传回路径
1016            Exit Function
1017        End If
1018        Index = Index + 1
1019   Loop
1020   PathReg = ""
End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-25 07:49 , Processed in 0.084946 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表