|
-
Aug 22nd, 2006, 05:12 PM
#1
Thread Starter
Hyperactive Member
[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?
Last edited by Fedhax; Aug 22nd, 2006 at 05:14 PM.
Reason: Minor Corrections
-
Aug 22nd, 2006, 05:17 PM
#2
PowerPoster
Re: Detecting OCX Files
look in the registry for the key ..
example the MsFlex thing is this ..
{6262D3A0-531B-11CF-91F6-C2863C385E30}
-
Aug 22nd, 2006, 05:28 PM
#3
Thread Starter
Hyperactive Member
Re: Detecting OCX Files
 Originally Posted by rory
look in the registry for the key ..
example the MsFlex thing is this ..
{6262D3A0-531B-11CF-91F6-C2863C385E30}
So I would need to verify that the file physically exists on the machine along side with the registry key for the OCX file? This solution is about as close as I'll get to being able to tell if a file is accessible to my program?
Also, surely someone has written a module or has source code that would do both of these things, or am I left with hoofing it?
-
Aug 22nd, 2006, 05:34 PM
#4
PowerPoster
Re: Detecting OCX Files
The OCX's i work with, and some codecs, are always in the same place in the registry ... it will differ from one to the next .. as they come out with a newer version it may change ... though ones im working with for remote video have been the same across 10+ version releases ...
So what i do, cause i include them in my program as well, i check the location, then i check the registry ... if they arent there i copy them to the location, then register them, in my case (and most all), System32.
So simply you need Registry Query Functions to see if its registered, then if not shell to the RegSvr command ... also have to first make sure the OCX exists in the System32 folder.
Last edited by rory; Aug 22nd, 2006 at 06:55 PM.
-
Aug 22nd, 2006, 06:39 PM
#5
PowerPoster
Re: Detecting OCX Files
here i threw this together for yah ...
You will need to Copy MSFLXGRD.OCX to your App/Project folder to test
as i didnt include it in the zip file.
Last edited by rory; Aug 23rd, 2006 at 09:32 AM.
-
Aug 23rd, 2006, 12:21 PM
#6
Thread Starter
Hyperactive Member
-
Aug 23rd, 2006, 12:29 PM
#7
PowerPoster
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.
-
Aug 23rd, 2006, 12:37 PM
#8
PowerPoster
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
-
Aug 23rd, 2006, 12:45 PM
#9
PowerPoster
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
-
Aug 23rd, 2006, 02:16 PM
#10
Thread Starter
Hyperactive Member
 Originally Posted by rory
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.
You raise an interesting question, and I figured that I'd throw it out there.
I want to keep all of my program's DLLs within the application's folder ( e.g. App.Path & "\DLLs" ) to ensure that everything is kept in a tidy location and should be simple to uninstall/remove. I know that programmers through the annuals of history have debated between Shared Libraries and Isolated Libraries where everything is self-contained. Where does that debate currently stand? I can't imagine the save space/save memory issue is a problem with 50+ GB HDs and default RAM builds going 512+ MB, but I could be wrong/out of touch here.
-
Aug 23rd, 2006, 02:21 PM
#11
PowerPoster
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 ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|