RegSvr32

Hi,

In VB, I was able to shell out to a window and use the RegSvr32 command and register a DLL or OCX, like so:

Dim vShell as Variant
vShell = Shell("regsvr32 /s " & strPath, vbNormalFocus)

Does anyone know how I can accomplish this in C# (vs2005)



Answer this question

RegSvr32

  • Ragin Cajun

    Try following:

    string strPath;

    //initialize strPath to the path of the file you want to register

    System.Diagnostics.Process.Start("regsvr32 /s " + strPath);


  • bchadraa MSFT

    Ok, what I thought was working, isn't. After trapping the error, I get a "File not Found" error. But this is impossible because the file exists in the exact spot it's looking for it.

    Has anyone else had this issue

    Here's the error:

    System.Exception: The following DLL did not register.
    c:\adacel\maxsim whiteboard\35\WBCustomObjects.dll
    Reason:
    System.ComponentModel.Win32Exception: The system cannot find the file specified
    at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
    at System.Diagnostics.Process.Start()
    at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
    at System.Diagnostics.Process.Start(String fileName)
    at MaxSimWhiteboard.frmMain.btnOk_Click(Object sender, EventArgs e)
    at MaxSimWhiteboard.frmMain.btnOk_Click(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


  • Anuj Purwar

    Thanks a million.
  • Al33327

    Yes, it works from the command line or the run line..

    After much research on the internet (and thanks to google) I found the solution:

    //Create the paths for the controls and DLLs.
    sPath[0] = sRootPath + sVersionParam + @"\WBCustomObjects.dll";
    sPath[1] = sRootPath + sVersionParam +
    @"\WBGred.dll";
    sPath[2] = sRootPath + sVersionParam +
    @"\WBInterfaces.dll";
    sPath[3] = sRootPath + sVersionParam +
    @"\WBGredOcx.ocx";

    Process p = new Process();
    p.StartInfo.FileName =
    @"regsvr32.exe";
    p.StartInfo.UseShellExecute =
    false;

    //Register the controls and DLLs.

    try
    {
         for (i = 0; i < sPath.Length; i++)
            {
                
    p.StartInfo.Arguments = " /s" + "\"" + sPathIdea + "\"";
                 p.Start();
                 p.Close();
           
    }
    }
    catch (Exception ex)
    {
                
    throw new Exception("The following DLL did not register.\n" + sPathIdea + "\n Reason:\n" + ex, ex.InnerException);
    }

    Where sRootPath = @"c:\windows apps\maxsim whiteboard\"
    AND sVersionParams = @"35"

    That works my friends!

     


  • spicoli7

    Does regsvr32 call for registering the same dll work from outside I mean from Windows/Run or command prompt etc.
  • RegSvr32