|
Поиск установленных приложений из пакета MS Office |
|
|
Иногда для работы вашего приложения требуется знать, какие программы из пакета Microsoft Office уже установлены на клиентском компьютере. Приведенный ниже пример показывает как это сделать средствами Visual Basic. 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_SZ = 1
Private Const REG_EXPAND_SZ = 2
Private Const ERROR_SUCCESS = 0
Const HKEY_CLASSES_ROOT = &H80000000
Function GetRegString(hKey As Long, strSubKey As String, strValueName As String) As String
Dim strSetting As String
Dim lngDataLen As Long
Dim lngRes As Long
If RegOpenKey(hKey, strSubKey, lngRes) = ERROR_SUCCESS Then
strSetting = Space(255)
lngDataLen = Len(strSetting)
If RegQueryValueEx(lngRes, strValueName, 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(lngRes) <> ERROR_SUCCESS Then
MsgBox "RegCloseKey Failed: " strSubKey, vbCritical
End If
End If
End Function
Public Function IsAppPresent(strSubKey$, strValueName$) As Boolean
IsAppPresent = CBool(Len(GetRegString(HKEY_CLASSES_ROOT, strSubKey, strValueName)))
End Function
Private Sub Form_Paint()
Print "Access " & IsAppPresent("Access.Database\CurVer",
"")
Print "Excel " & IsAppPresent("Excel.Sheet\CurVer", "")
Print "PowerPoint " & IsAppPresent("PowerPoint.Slide\CurVer",
"")
Print "Word " & IsAppPresent("Word.Document\CurVer", "")
End Sub
|
|
|
|
|
|
|