Results 1 to 10 of 10

Thread: VB Snippet - Register / unRegister dll/ocx thru Code

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Register / unRegister dll/ocx thru Code

    VB Code:
    1. ' REGISTERS ACTIVE X
    2.  
    3. Shell "REGSVR32 -S \ACTIVEXPATH\DLL OR OCX NAME"
    4.  
    5.  
    6. ' UNREGISTERS ACTIVE X
    7.  
    8. Shell "REGSVR32 -S -U \ACTIVEXPATH\DLL OR OCX NAME"
    9.  
    10. ' - S = DON'T SHOW DIALOG BOX
    11.  
    12. ' - U  = UNREGISTER
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    I am trying to put this in a simple program. That will allow users to search for the file on there hard drive and load its location into a textbox. For instance, When the file is loaded Text1 tells the complete path to the file and the file name. I am trying to get this code to register the file using


    Code:
    Private Sub Command1_Click()
    Shell "REGSVR32 -S\" & Text1.Text 
    End Sub
    I take it i'm doing this wrong...Any help would be greatly appreciated.....thx
    [vbcode]Private Sub Form_Load()
    I would rather be hated for who I am than loved for who I'm not.[/vbcode]
    End Sub

  3. #3
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545

    Here is a pretty straight forward example I cooked up for you.

    -You will need a text1, list1 and command1 on your form.
    -You will need to reference "Microsoft Scripting Runtime"
    -You will need to type in the name of the dll or ocx file that you are searching for. After that, click on command1 to search.
    -List1 will shows all location this file existed.
    Code:
    Option Explicit
    
    Dim mblnEnd  As Boolean
    Private Sub Command1_Click()
        Dim strPath As String
        strPath = InputBox("Enter the starting path.", "Path", "C:\")
        mblnEnd = False
        
        List1.Clear
        Call sFindFile(strPath)
        
        Me.MousePointer = vbDefault
        MsgBox "Done Searching"
    End Sub
    
    Private Sub sFindFile(strFolder As String)
        Me.MousePointer = vbHourglass
        If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
        
        Dim FSO As New FileSystemObject
        If FSO.FolderExists(strFolder) = False Then Exit Sub
        
        Dim strFullFile As String
        Dim fldFile As File
        On Error GoTo Error_Handler
        For Each fldFile In FSO.GetFolder(strFolder).Files
            If LCase(fldFile.Name) = LCase(Text1.Text) Then
                List1.AddItem fldFile.Path       'Add every time there is a match
                strFullFile = Chr$(34) & fldFile.Path & Chr$(34)
                If MsgBox("Do you want to register this file?" & vbCrLf & strFullFile, vbYesNo) = vbYes Then
                    Call Shell("Regsvr32.exe /s " & strFullFile)
                End If
                
                If MsgBox("Continue to search for other copies of this file?" & vbCrLf & Text1.Text, vbYesNo) = vbNo Then
                    mblnEnd = True
                End If
                
                Exit For    'No need to check other files
            End If
        Next
        Set fldFile = Nothing
        
        'PURPOSE: Check for subfolders
        Dim fldSubFolder As Folder
        For Each fldSubFolder In FSO.GetFolder(strFolder).SubFolders
            If mblnEnd = True Then Exit Sub
            
            Call sFindFile(fldSubFolder.Path)       'Recursive
        Next
        Set fldSubFolder = Nothing
        Set FSO = Nothing
        Exit Sub
        
    Error_Handler:
        Debug.Print "System Directory - Unable to check in this directory: "
        Debug.Print strFolder
    End Sub
    Last edited by Hawk; Feb 23rd, 2003 at 05:43 AM.
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  4. #4
    Thanks, i will try that out.
    [vbcode]Private Sub Form_Load()
    I would rather be hated for who I am than loved for who I'm not.[/vbcode]
    End Sub

  5. #5
    I'm getting an Error in the Dim Statement for
    Dim FSO as New FileSystemObject

    VB Code:
    1. Private Sub sFindFile(strFolder As String)
    2.     Me.MousePointer = vbHourglass
    3.     If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
    4.    
    5.     Dim FSO As New FileSystemObject
    6.     If FSO.FolderExists(strFolder) = False Then Exit Sub
    7.    
    8.     Dim strFullFile As String
    9.     Dim fldFile As File
    10.     On Error GoTo Error_Handler
    11.     For Each fldFile In FSO.GetFolder(strFolder).Files
    12.         If LCase(fldFile.Name) = LCase(Text1.Text) Then
    13.             List1.AddItem fldFile.Path       'Add every time there is a match
    14.             strFullFile = Chr$(34) & fldFile.Path & Chr$(34)
    15.             If MsgBox("Do you want to register this file?" & vbCrLf & strFullFile, vbYesNo) = vbYes Then
    16.                 Call Shell("Regsvr32.exe /s " & strFullFile)
    17.             End If
    18.            
    19.             If MsgBox("Continue to search for other copies of this file?" & vbCrLf & Text1.Text, vbYesNo) = vbNo Then
    20.                 mblnEnd = True
    21.             End If
    22.            
    23.             Exit For    'No need to check other files
    24.         End If
    25.     Next
    26.     Set fldFile = Nothing
    27.    
    28.     'PURPOSE: Check for subfolders
    29.     Dim fldSubFolder As Folder
    30.     For Each fldSubFolder In FSO.GetFolder(strFolder).SubFolders
    31.         If mblnEnd = True Then Exit Sub
    32.        
    33.         Call sFindFile(fldSubFolder.Path)       'Recursive
    34.     Next
    35.     Set fldSubFolder = Nothing
    36.     Set FSO = Nothing
    37.     Exit Sub
    38.    
    39. Error_Handler:
    40.     Debug.Print "System Directory - Unable to check in this directory: "
    41.     Debug.Print strFolder
    42. End Sub
    [vbcode]Private Sub Form_Load()
    I would rather be hated for who I am than loved for who I'm not.[/vbcode]
    End Sub

  6. #6
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545
    Actually, I should have left that line on a module level so it does not have to recreate the dim for every sub folder.

    Back to your problem. Did you reference "Microsoft Scripting Runtime"?
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  7. #7
    excuse the no0b coming out in me. But i've never delt with Microsoft Scripting Refrence. So could u please be more detailed as to what this is......Thankx
    [vbcode]Private Sub Form_Load()
    I would rather be hated for who I am than loved for who I'm not.[/vbcode]
    End Sub

  8. #8
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545
    No problem.

    Go up to the Project Menu and click on References. Once the dialog box open, scroll down to that and click on "Microsoft Scripting Runtime". Done!
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  9. #9
    New Member
    Join Date
    Dec 2002
    Location
    Didsbury, Alberta
    Posts
    9

    Thumbs up

    This little script works great and registers the DLL that I want.
    After reviewing my Project References, The DLL that I want is listed. Great!
    Last edited by chil; Mar 11th, 2003 at 02:43 PM.

  10. #10
    Hyperactive Member phrozeman's Avatar
    Join Date
    Apr 2000
    Location
    Netherlands
    Posts
    442
    i use this class to register DLL/OCX

    no regsvr32 required!!!

    Usage
    VB Code:
    1. Dim reg As RegService.clsRegDLL
    2.  
    3. Private Sub Command1_Click()
    4. Dim menum As Status
    5. Set reg = New RegService.clsRegDLL
    6. If reg.RegisterComponent(Trim$(Text1.Text), DllRegisterServer) = 5 Then MsgBox "Successfull!"
    7. End Sub
    Attached Files Attached Files
    There's a certain mystique when I speak, that you notice that it's sorta unique, cause you know it's me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width