Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Running regsvr32.exe from CreateProcess

Running regsvr32.exe from CreateProcess

Scheduled Pinned Locked Moved Visual Basic
questioncomhelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Barry True
    wrote on last edited by
    #1

    This is actually a VB6 question. I'm trying to set up a VB DLL so that if it can't instantiate an external COM object because it is not registered properly it would run regsvr32.exe against the DLL to register the object and then try to instantiate it again. I'm using CreateProcess to run regsvr32 against the DLL and the problem I'm running into is that when the CreateProcess method is invoked, regsvr32 generates a dialog box indicating that LoadLibrary can't find the specified module. The module it prints out is the correct path to the DLL. Does anyone know how I can get this working?

    D A 2 Replies Last reply
    0
    • B Barry True

      This is actually a VB6 question. I'm trying to set up a VB DLL so that if it can't instantiate an external COM object because it is not registered properly it would run regsvr32.exe against the DLL to register the object and then try to instantiate it again. I'm using CreateProcess to run regsvr32 against the DLL and the problem I'm running into is that when the CreateProcess method is invoked, regsvr32 generates a dialog box indicating that LoadLibrary can't find the specified module. The module it prints out is the correct path to the DLL. Does anyone know how I can get this working?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I'm not sure, but it sounds like you're passing in a path to the .DLL that includes spaces. You'll have to enclose the path in double quote marks so the command line you pass to CreateProcess looks more like this:

      REGSVR32 "C:\\Program Files\\Folder\\Some Folder\\MYDLL.DLL"
      

      If not, RegSvr32 will look for a file called "Program" at the root of C:, not MYDLL.DLL in the path you want. To build the path string with quote marks inside it, you have to use 2 quotes to get 1:

      Dim path As String = """C:\\Program Files\\Folder...MYDLL.DLL"""
      

      Dave Kreskowiak Microsoft MVP - Visual Basic

      B 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I'm not sure, but it sounds like you're passing in a path to the .DLL that includes spaces. You'll have to enclose the path in double quote marks so the command line you pass to CreateProcess looks more like this:

        REGSVR32 "C:\\Program Files\\Folder\\Some Folder\\MYDLL.DLL"
        

        If not, RegSvr32 will look for a file called "Program" at the root of C:, not MYDLL.DLL in the path you want. To build the path string with quote marks inside it, you have to use 2 quotes to get 1:

        Dim path As String = """C:\\Program Files\\Folder...MYDLL.DLL"""
        

        Dave Kreskowiak Microsoft MVP - Visual Basic

        B Offline
        B Offline
        Barry True
        wrote on last edited by
        #3

        I am but I am enclosing the path in double-quotes. I found this out the first time I tried it without double-quotes. Regsvr32 complained about not being able to find the C:\Program component. What I found was that I could set up an console app built in Visual C++ to do this and it worked fine if I ran it from the command line. But if I called the Visual C++ executable from my VB app, it gave me the same error. It looks like it has something to do with trying to run regsvr32.exe from a VB instantiated thread.

        D 1 Reply Last reply
        0
        • B Barry True

          I am but I am enclosing the path in double-quotes. I found this out the first time I tried it without double-quotes. Regsvr32 complained about not being able to find the C:\Program component. What I found was that I could set up an console app built in Visual C++ to do this and it worked fine if I ran it from the command line. But if I called the Visual C++ executable from my VB app, it gave me the same error. It looks like it has something to do with trying to run regsvr32.exe from a VB instantiated thread.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          I never had a problem running RegSvr32 from VB6 or VB.NET. Since a process gets it's own seperate thread, regardless of which thread you create it from in your app, I don't see how this would cause a problem. Hmmm... Are you running multiple copies of RegSvr32 at the same time? (grasping at straws here...)

          Dave Kreskowiak Microsoft MVP - Visual Basic

          B 2 Replies Last reply
          0
          • B Barry True

            This is actually a VB6 question. I'm trying to set up a VB DLL so that if it can't instantiate an external COM object because it is not registered properly it would run regsvr32.exe against the DLL to register the object and then try to instantiate it again. I'm using CreateProcess to run regsvr32 against the DLL and the problem I'm running into is that when the CreateProcess method is invoked, regsvr32 generates a dialog box indicating that LoadLibrary can't find the specified module. The module it prints out is the correct path to the DLL. Does anyone know how I can get this working?

            A Offline
            A Offline
            arcticbrew
            wrote on last edited by
            #5

            As an alternative to regsvr32, you could (pinvoke) call the DllRegisterServer function in the Dll. Regsvr32 executes this function in the Dll to perform the registration.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              I never had a problem running RegSvr32 from VB6 or VB.NET. Since a process gets it's own seperate thread, regardless of which thread you create it from in your app, I don't see how this would cause a problem. Hmmm... Are you running multiple copies of RegSvr32 at the same time? (grasping at straws here...)

              Dave Kreskowiak Microsoft MVP - Visual Basic

              B Offline
              B Offline
              Barry True
              wrote on last edited by
              #6

              I'm just setting up the command line in a string and passing the string to CreateProcess like this: Dim cmdLine as String cmdLine = "regsvr32.exe " & Chr(34) & "C:\Program Files\ProgramFilesFolder\DllFilename.dll") I'm passing a NULL string for the application name, a NULL for the process attributes and thread attributes, not inheriting the handles, NORMAL_PRIORITY_CLASS for the priority class, NULL for the environment pointer and current directory, and pointers to a startup info and process info structure with just the sizes set in both. Should any of these parameters on the CreateProcess call be set differently?

              B 1 Reply Last reply
              0
              • B Barry True

                I'm just setting up the command line in a string and passing the string to CreateProcess like this: Dim cmdLine as String cmdLine = "regsvr32.exe " & Chr(34) & "C:\Program Files\ProgramFilesFolder\DllFilename.dll") I'm passing a NULL string for the application name, a NULL for the process attributes and thread attributes, not inheriting the handles, NORMAL_PRIORITY_CLASS for the priority class, NULL for the environment pointer and current directory, and pointers to a startup info and process info structure with just the sizes set in both. Should any of these parameters on the CreateProcess call be set differently?

                B Offline
                B Offline
                Barry True
                wrote on last edited by
                #7

                Sorry. In the previous example I should have added the trailing Chr(34) for the ending set of double-quotes instead of the end paren.

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  I never had a problem running RegSvr32 from VB6 or VB.NET. Since a process gets it's own seperate thread, regardless of which thread you create it from in your app, I don't see how this would cause a problem. Hmmm... Are you running multiple copies of RegSvr32 at the same time? (grasping at straws here...)

                  Dave Kreskowiak Microsoft MVP - Visual Basic

                  B Offline
                  B Offline
                  Barry True
                  wrote on last edited by
                  #8

                  I'm not running multiple copies of regsvr32 that I'm aware of. The only thing I can think of that would cause problems is that the process that I'm invoking regsvr32 from doesn't have admin privileges. However, I can set up a test app using VB and run it from an account that I know have admin privileges and I get the same results. If I set up a Visual C++ app that does the same exact thing as the VB test app, it works perfectly. -- modified at 12:37 Monday 5th March, 2007

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups