Results 1 to 10 of 10

Thread: using regsvr32

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    MinneSoCold
    Posts
    2

    Smile using regsvr32

    In my job I test software applications. To make it easier for me to reinstall new builds I wrote a batch file to unregister the dlls used by one of our apps. (it will not uninstall otherwise) The batch file is very simple: "regsvr32 -u c:\....filename.dll" I would like to convert this to a visual basic 6 application. Clicking a command button to do what the batch file does, another command button to exit and a couple of labels. Should be really simple but I am stuck. I have tried the shell execute function to run regsvr32, I get no error messages but it doesn't work. For something this simple should I be able to use the open command? Nothing I have tried so far appears to work. eg: open "regsvr32.exe -u <path> for binary as #1
    Close#1" That statement gives me a whole host of syntex and compile errors. Any suggestions?

    thanks,
    Myra

  2. #2
    Matthew Gates
    Guest
    Looks like you are using the wrong parameter the wrong way.


    VB Code:
    1. Shell "RegSvr32 /u C:\...filename", 1

    And if your wanting to put it into a batch file...


    VB Code:
    1. Private Sub Command1_Click()
    2.     Open "C:\RegBat.bat" For Output As #1
    3.         Print #1, "@ECHO OFF"
    4.         Print #1, "@RegSvr32 /u C:\...filename"
    5.     Close #1
    6.    
    7.     DoEvents
    8.  
    9.     Shell "C:\RegBat.bat"
    10. End Sub

  3. #3
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    Try this link. It shows you how to register and un-register ActiveX controls using VB.

  4. #4
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810

    API

    Code:
    '// These are API calls reqired for registering/unregistering ActiveX DLLs & OCXs   //
    Declare Function LoadLibraryRegister _
            Lib "kernel32" Alias "LoadLibraryA" _
            (ByVal lpLibFileName As String) As Long
      
    Declare Function CreateThreadForRegister _
            Lib "kernel32" Alias "CreateThread" _
            (lpThreadAttributes As Any, ByVal dwStackSize _
            As Long, ByVal lpStartAddress As Long, _
            ByVal lParameter As Long, ByVal dwCreationFlags As Long, _
            lpThreadID As Long) As Long
       
    Declare Function WaitForSingleObject _
            Lib "kernel32" (ByVal hHandle As Long, _
            ByVal dwMilliseconds As Long) As Long
       
    Declare Function GetProcAddressRegister _
            Lib "kernel32" Alias "GetProcAddress" _
            (ByVal hModule As Long, ByVal lpProcName As String) _
            As Long
    
    Declare Function FreeLibraryRegister Lib _
            "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) _
            As Long
    
    Declare Function CloseHandle Lib "kernel32" _
            (ByVal hObject As Long) As Long
    
    Declare Function GetExitCodeThread Lib "kernel32" _
            (ByVal hThread As Long, lpExitCode As Long) As Long
    
    Declare Sub ExitThread Lib "kernel32" _
            (ByVal dwExitCode As Long)
    
    
    Private Function RegSvr32(ByVal FileName As String, bUnReg As _
       Boolean) As Boolean
    
    Dim lLib As Long
    Dim lProcAddress As Long
    Dim lThreadID As Long
    Dim lSuccess As Long
    Dim lExitCode As Long
    Dim lThread As Long
    Dim bAns As Boolean
    Dim sPurpose As String
    
    sPurpose = IIf(bUnReg, "DllUnregisterServer", _
      "DllRegisterServer")
    
    If Dir(FileName) = "" Then Exit Function
    
    lLib = LoadLibraryRegister(FileName)
    'could load file
    If lLib = 0 Then Exit Function
    
    lProcAddress = GetProcAddressRegister(lLib, sPurpose)
    
    If lProcAddress = 0 Then
      'Not an ActiveX Component
       FreeLibraryRegister lLib
       Exit Function
    Else
       lThread = CreateThreadForRegister(ByVal 0&, 0&, ByVal lProcAddress, ByVal 0&, 0&, lThread)
       If lThread Then
            lSuccess = (WaitForSingleObject(lThread, 10000) = 0)
            If Not lSuccess Then
               Call GetExitCodeThread(lThread, lExitCode)
               Call ExitThread(lExitCode)
               bAns = False
               Exit Function
            Else
               bAns = True
            End If
            CloseHandle lThread
            FreeLibraryRegister lLib
       End If
    End If
        RegSvr32 = bAns
    End Function
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    MinneSoCold
    Posts
    2

    using regsvr32

    Thanks! I tried

    Shell "RegSvr32 /u C:\...filename", 1

    and it works like a charm. I did not realize you could use Shell. I had been trying to call the api function shellexecute and it kept getting more and more complicated.

    The only thing I needed to add was a /s switch to suppress the message boxes from regsvr.

    Myra

  6. #6
    Junior Member
    Join Date
    Nov 2000
    Location
    IL, USA
    Posts
    17

    Angry While we're on the subject of RegSvr32...

    I have been having a problem on my winME PC at home. When I logout of a windows session I get an application error for the regsvr32 saying that the program has errored and will now close. If I don't OK this before too long the PC hangs up until manually shut down.

    I know that this regsvr32 program is supposed to be cleaning up dll info in the registry (correct?) and runs at logout/shutdown and that it is a system application, so I have not tried to replace it with any other version.

    Has anyone had this problem before or does anyong have any idea what is going wrong? I would really appreciate it if you could help.

    Thanks,

    nobair

  7. #7
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    An even better way...

    You will love this. I don't know who came up wtih this or who
    wrote the reg file. This reg file will add items to the Explore right
    click menu that will allow you to register and unregister ocx and
    dll files.

    This forum won't let me upload *.reg files so I've included the
    contents of the file below. Copy the contents below and then
    paste them into a new text document in NotePad. Save the file
    with a REG extention (e.g. Adddll.reg) and then double click on it
    in Explorer.

    For now on you can right click on ocx and dll files to register them
    and unregister them.

    REGEDIT4
    ; This adds the ability to Right-Click on a .dll or .ocx
    ; and get the Register / UnRegister options.

    ; ==========
    ; .DLL files
    ; ==========

    [HKEY_CLASSES_ROOT\.dll]
    "Content Type"="application/x-msdownload"
    @="dllfile"

    [HKEY_CLASSES_ROOT\dllfile]
    @="Application Extension"

    [HKEY_CLASSES_ROOT\dllfile\Shell\Register\command]
    @="regsvr32.exe \"%1\""

    [HKEY_CLASSES_ROOT\dllfile\Shell\UnRegister\command]\
    @="regsvr32.exe /u \"%1\""

    ; ==========
    ; .OCX files
    ; ==========

    [HKEY_CLASSES_ROOT\.ocx]
    @="ocxfile"

    [HKEY_CLASSES_ROOT\ocxfile]
    @="OCX"

    [HKEY_CLASSES_ROOT\ocxfile\Shell\Register\command]
    @="regsvr32.exe \"%1\""

    [HKEY_CLASSES_ROOT\ocxfile\Shell\UnRegister\command]
    @="regsvr32.exe /u \"%1\""

    ; End
    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  8. #8
    Junior Member
    Join Date
    Nov 2000
    Location
    IL, USA
    Posts
    17

    Thumbs up That IS Really Cool...

    Thanks, gdebacker! This is awesome!

    This leads me to two more questions.

    1. How do I stop regsvr32 firing when windows closes?

    2. How can I change this to make my own right click menu entries?
    I think it would be cool to create a 'Goto ->' menu option with a sub menu of shortcuts that take you to your DIR destination when opening a file from a program (other than Explorer). That way I wouldn't have to spend so much time climbing down a DIR path when attaching an email or going to a network path to open a file in XL.

    Could you suggest a reference for this 'Registry Programming' stuff or do you have anything up your sleve?????


    Anticipatingly Thankful,

    Nobair




  9. #9
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    1. How do I stop regsvr32 firing when windows closes?

    2. How can I change this to make my own right click menu entries? I think it would be cool to create a 'Goto ->' menu option with a sub menu of shortcuts that take you to your DIR destination when opening a file from a program (other than Explorer). That way I wouldn't have to spend so much time climbing down a DIR path when attaching an email or going to a network path to open a file in XL.
    Have know Idea why regsvr32 is running when you close. You
    can look at the Maintance Wizard to see if it is doing it. You could
    also try the MSConfig program to see if it is loading it, or scan the
    registry to see if you can find a place that it is being loaded from.

    As for number 2, you could try my Control Freak program (forgive me for promoting my own application) it allows you to setup a QuickList for folders, files, zip files, ftp sites, ect.. I am working on an upgrade now but the current version is quite useful. http://windsweptsoftware.com

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  10. #10
    Junior Member
    Join Date
    Nov 2000
    Location
    IL, USA
    Posts
    17
    The ControlFreak program is good. I am now using it instead of using different interfaces for the all of the apps that it includes.

    However, this doesn't really address the idea that I have about adding a menu item to the right click menu to allow the user to go to a directory when opening a file from another application, like Word.
    EXAMPLE: Open word, select open file, right click empty (white) space in file dialog box, select 'Goto ->' from context menu, select DIR destination MyFiles from sub menu, open file dialog goes to that dir, select the file without having to explor the entire path.

    Can I do this somehow (maybe I should start a new thread)?


    I would really appreciate any information I can get about this.


    nobair

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