[RESOLVED] Detecting OCX Files
I'm rather weary about posting this question, but I have spent upwards of a day searching through the forums here and through Google's results. When someone asks "How can I detect what OCX files have been installed on an end user's system?", the answers usually end up along the lines of "Why care? Make an installer, register it, and forget about it." End of discussion.
Now, this answer is fine for the initial installation, but I want to be able to check for these things every time the application is started. Instead of throwing out an error message--even if it is through my error handling routines--"429: Unable to create object", I'd like to then go through a check list and see which files are causing this 429 error. Maybe a software reinstall will fix it, but for the sake of testing--and for the sake of my testers--I'd like to give something more tangible to bite on especially since my testers are also computer programmers. Heck, if I knew exactly how the error was occuring, maybe I could do some fixes behind the scenes without the end user noticing--unless they look in the log file.
I've seen code where you try to verify if a DLL is registered:
VB Code:
Public Function Foo() As Boolean
On Error Goto EndofFoo
Dim lb as Boolean
Dim lo as Object
Set lo = CreateObject("Dll.Class")
lb = True
Foo = lb
Exit Function
EndofFoo:
lb = False
Foo = lb
End Function
However, if I want to see if they have/need MSFlxGrd.OCX, what would I do to check for it, or is it even possible?
Re: [RESOLVED] Detecting OCX Files
Yes once you register the OCX in a particular folder, if you move it, it wont work. However when you reregister it, other programs that use it should automatically use that new folder location, as that info is what is in the registry.
You really want to keep the default location though.
Re: [RESOLVED] Detecting OCX Files
to register it no matter whether there is a path value in the registry or not ...
VB Code:
'// CHECK OCX AND REGISTER IF NOT
Public Function Register(ByVal CLSID As String, _
ByVal FILEX As String) As Boolean
Dim RegVer As String
Dim RegOcx As String
Dim TmpOcx As String
On Error GoTo Error_Handler:
'CHECK CLSID & FILE VALUES
If Right(LCase(FILEX), 4) = ".ocx" And LenB(CLSID) > 0 Then
RegOcx = SystemDirectory & "\" & FILEX
TmpOcx = App.Path & "\" & FILEX
'IF NOT IN SYSTEM DIRECTORY COPY
If LenB(Dir$(RegOcx)) = 0 Then
'IF TMP OCX EXISTS
If LenB(Dir$(TmpOcx)) > 0 Then
FileCopy TmpOcx, RegOcx
Else
'CANT COPY SO EXIT
Exit Function
End If
End If
'IF IN SYSTEM DIRECTORY NOW
If LenB(Dir$(RegOcx)) > 0 Then
Shell "regsvr32 -s " & RegOcx
Else
'CANT REG SO EXIT
Exit Function
End If
'CHECK THAT IT IS REGISTERED
RegVer = Query_Value(HKEY_CLASSES_ROOT, "CLSID\{" & CLSID & "}\InprocServer32", "")
If InStr(1, RegVer, RegOcx, 3) And LenB(Dir$(RegOcx)) > 0 Then
Register = True
End If
End If
Exit Function
Error_Handler:
Register = False
End Function
Re: [RESOLVED] Detecting OCX Files
and if you dont even need to see if it is in the registry first ..
just check the system directory, if not there copy the ocx,
then register it with regsvr.
VB Code:
'// TEST BUTTON
Private Sub Command1_Click()
If Register("Msflxgrd.ocx") Then
Debug.Print "Registered Successfully"
Else
Debug.Print "Error Registering"
End If
End Sub
'// REGISTER OCX FILE
Public Function Register(ByVal FILEX As String) As Boolean
Dim RegOcx As String
Dim TmpOcx As String
On Error GoTo Error_Handler:
'CHECK CLSID & FILE VALUES
If Right(LCase(FILEX), 4) = ".ocx" Then
RegOcx = SystemDirectory & "\" & FILEX
TmpOcx = App.Path & "\" & FILEX
'IF NOT IN SYSTEM DIRECTORY COPY
If LenB(Dir$(RegOcx)) = 0 Then
'IF TMP OCX EXISTS
If LenB(Dir$(TmpOcx)) > 0 Then
FileCopy TmpOcx, RegOcx
Else
'CANT COPY SO EXIT
Exit Function
End If
End If
'IF IN SYSTEM DIRECTORY NOW
If LenB(Dir$(RegOcx)) > 0 Then
Shell "regsvr32 -s " & RegOcx
Else
'CANT REG SO EXIT
Exit Function
End If
Register = True
End If
Exit Function
Error_Handler:
Register = False
End Function
'// GET WINDOWS SYSTEM DIRECTORY
Private Function SystemDirectory()
Dim objFso As Object
Set objFso = CreateObject("scripting.filesystemobject")
SystemDirectory = objFso.GetSpecialFolder(1)
End Function
Re: [RESOLVED] Detecting OCX Files
Are they your own Custom Made DLLs or others?
If they are your own then sure ... GeoVision's (popular PC DVR Card) software keeps all their own DLLs in their folder ... they keep the setting's Ini files in the windows directory .. so the settings arent uninstalled unless manually deleted or windows reloaded ..