判断DCOM是否已安装 Private Function DCOMOK() As Boolean 'Determine if DCOM (Distributed COM) can be used. It can if it 'is installed and is enabled on the current machine. 'Dim bOK As Boolean Dim bPresent As Boolean Dim bEnabled As Boolean Dim hKey As Long Dim lpType As Long Dim lpData Dim lResult As Long Dim lpcbData As Long
lResult = GetProcAddress(GetModuleHandle("OLE32"), "CoInitializeEx") If lResult <> 0 Then bPresent = True Else bPresent = False End If
Private Function DCOMOK() As Boolean
'Determine if DCOM (Distributed COM) can be used. It can if it
'is installed and is enabled on the current machine.
'Dim bOK As Boolean
Dim bPresent As Boolean
Dim bEnabled As Boolean
Dim hKey As Long
Dim lpType As Long
Dim lpData
Dim lResult As Long
Dim lpcbData As Long
lResult = GetProcAddress(GetModuleHandle("OLE32"), "CoInitializeEx")
If lResult <> 0 Then
bPresent = True
Else
bPresent = False
End If
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Ole", 0, _
KEY_ALL_ACCESS, hKey)
lpcbData = Len("EnableDCOM") '10
If lResult = ERROR_SUCCESS Then
lResult = RegQueryValueEx(ByVal hKey, "EnableDCOM", 0, ByVal lpType, lpData, lpcbData)
End If
If lResult = ERROR_SUCCESS Then
bEnabled = True
RegCloseKey (hKey)
Else
bEnabled = False
End If
If bEnabled And bPresent Then
DCOMOK = True
Else
DCOMOK = False
End If
End Function