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




Reply With Quote