Office中国论坛/Access中国论坛
标题:
在VB中怎样判断系统中是否安装ACCESS?,
[打印本页]
作者:
xinle
时间:
2008-5-30 11:19
标题:
在VB中怎样判断系统中是否安装ACCESS?,
在VB中怎样判断系统中是否安装ACCESS?,
没有装就提示用户用户安装,
已经安装则提示安装路径及Access版本.
我目前用的是 CreateObject 方法,
如果不允许用 CreateObject 方法,
不知是否有更好的方法.
谢谢!
作者:
tmtony
时间:
2008-5-30 12:04
可以检测注册项
或者使用createobject, 捕获错误,如何出错,则可根据返回信息,判断是否对象不存在
作者:
rjacky
时间:
2008-5-30 13:08
不用creatobject的话,比较方便的就是检测注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office 下的键值了
作者:
rjacky
时间:
2008-5-30 13:19
从别处转贴过来的,仅供参考
Option Explicit
Private Declare Function RegOpenKey Lib "advapi32" Alias "RegOpenKeyA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) _
As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
lpReserved As Long, _
lptype As Long, _
lpData As Any, _
lpcbData As Long) _
As Long
Private Declare Function RegCloseKey& Lib "advapi32" (ByVal hKey&)
Private Const REG_EXPAND_SZ = 2
Private Const ERROR_SUCCESS = 0
Private Const HKEY_CLASSES_ROOT = &H80000000
Public Function IsAppPresent(ByVal strSubKey$) As Boolean
IsAppPresent = CBool(Len(GetRegString(HKEY_CLASSES_ROOT, strSubKey)))
End Function
Private Sub Command1_Click()
Label1.Caption = "Access : " & IsAppPresent("Access.Database\CurVer")
Label2.Caption = "Excel :" & IsAppPresent("Excel.Sheet\CurVer")
Label3.Caption = "PowerPoint :" & IsAppPresent("PowerPoint.Slide\CurVer")
Label4.Caption = "Word :" & IsAppPresent("Word.Document\CurVer")
End Sub
Public Function GetRegString(ByVal hKey As Long, _
ByVal strSubKey As String) As String
Dim strSetting As String
Dim lngDataLen As Long
Dim lnghResult As Long
If RegOpenKey(hKey, strSubKey, lnghResult) = ERROR_SUCCESS Then
strSetting = Space$(255)
lngDataLen = Len(strSetting)
'lpValueName为vbNullString只读取其默认值
If RegQueryValueEx(lnghResult, vbNullString, ByVal 0, _
REG_EXPAND_SZ, ByVal strSetting, lngDataLen) = ERROR_SUCCESS Then
If lngDataLen > 1 Then
GetRegString = Left$(strSetting, lngDataLen - 1)
End If
End If
If RegCloseKey(lnghResult) <> ERROR_SUCCESS Then
MsgBox "RegCloseKey Failed: " & strSubKey, vbCritical
End If
End If
End Function
复制代码
作者:
xinle
时间:
2008-5-30 15:10
谢谢,试试先
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3