Renat Tlebaldziyeu

Outlook Security Manager deployment: bitness and regsvr32 utility, part 2

As I mentioned in the first part of this series that highlighted the basics of Outlook Security Manager 2010 deployment for .NET, ActiveX and VCL, part 1, if your software uses the Outlook Security Manager component, you need to register one of the secman or osmax files depending on the Outlook version installed on a target PC. You register 64-bit files for Outlook 2010 64-bit only (supported by .net and ActiveX editions only), for other versions you register 32-bit ones.

How do you determine which file must be registered and how do you register it using the regsvr32 utility?

You can find the Outlook 2010 bitness by checking the Bitness value in the registry key below. The registry key to check is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Outlook

What to register?

The following function returns true if you have Outlook 2010 64-bit installed:

C#:

using Microsoft.Win32;
...
bool Is64BitOutlook()
{
    bool is64bit = false;
    bool isOutlook2010 = false;
 
    RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Outlook.Application\CurVer");
    if (key != null)
    {
        if (key.GetValue("") != null)
        {
            if (key.GetValue("").ToString() == "Outlook.Application.14") isOutlook2010 = true;
        }
    }            
 
    if (isOutlook2010)
    {
        key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Outlook");
        is64bit = true;
        if (key != null)
        {
            if (key.GetValue("Bitness") != null)
            {
                if (key.GetValue("Bitness").ToString() == "x86") is64bit = false;
            }
        }
    }
    return is64bit;
}

VB.NET:

Imports Microsoft.Win32
...
Function Is64BitOutlook() As Boolean
    Dim is64bit As Boolean = False
    Dim isOutlook2010 As Boolean = False
 
    Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey("Outlook.Application\CurVer")
    If Not (key Is Nothing) Then
        If Not (key.GetValue("") = Nothing) Then
            If (key.GetValue("").ToString() = "Outlook.Application.14") Then isOutlook2010 = True
            End If
    End If
 
    If (isOutlook2010) Then
        key = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Office\14.0\Outlook")
        is64bit = True
        If Not (key Is Nothing) Then
            If Not (key.GetValue("Bitness") = Nothing) Then
                If (key.GetValue("Bitness").ToString() = "x86") Then is64bit = False
            End If
        End If
    End If
 
    Return is64bit
End Function

So, if this function returns true, you register secman64.dll, if false – secman.dll.

How to register / unregister?

You use the regsvr32 utility to register a COM dll. The following function registers or unregisters a COM DLL, the full path of which of which is specified by the DllPath argument:

C#:

using System.IO;
using System.Diagnostics;
...
void RegisterComDll(string DllPath, bool UnRegister)
{
    Process RegProc = null;
    try
    {
         RegProc = new Process();
         RegProc.StartInfo.FileName = "\"" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "regsvr32.exe") + "\"";
         RegProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         if (!UnRegister) RegProc.StartInfo.Arguments = "/s \"" + DllPath + "\"";
         else RegProc.StartInfo.Arguments = "/s /u \"" + DllPath + "\"";
         RegProc.Start();
         RegProc.WaitForExit();
     }
     finally
     {
         if (RegProc != null)
         {
             RegProc.Close();
             RegProc.Dispose();
         }
     }
}

VB.NET:

Imports System.IO
Imports System.Diagnostics
…
Sub RegisterComDll(ByVal DllPath As String, ByVal UnRegister As Boolean)
    Dim RegProc As Process = Nothing
    Try
        RegProc = New Process()
        RegProc.StartInfo.FileName = """" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "regsvr32.exe") + """"
        RegProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        If Not (UnRegister) Then
            RegProc.StartInfo.Arguments = "/s """ + DllPath + """"
        Else
            RegProc.StartInfo.Arguments = "/s /u """ + DllPath + """"
        End If
        RegProc.Start()
        RegProc.WaitForExit()
    Finally
        If Not (RegProc Is Nothing) Then
            RegProc.Close()
            RegProc.Dispose()
        End If
    End Try
End Sub

The following parameters of the regsvr32 utility are used in the code above:

/u – Unregisters server (if UnRegister parameter = true)

/s – Specifies regsvr32 to run silently and to not display any message boxes.

Thus, using the functions above, you can write code that registers /unregisters 32-bit or  64-bit dlls, depending on the Outlook version installed on a target PC:

C#:

void RegisterSecmanDll(string DllPath, string Dll64Path, bool UnRegister)
{
    if (Is64BitOutlook())
       RegisterComDll(Dll64Path, UnRegister);
    else
       RegisterComDll(DllPath, UnRegister);
}

VB.NET:


Sub RegisterSecmanDll(ByVal DllPath As String, _
    ByVal Dll64Path As String, ByVal UnRegister As Boolean)
    If (Is64BitOutlook()) Then
        RegisterComDll(Dll64Path, UnRegister)
    Else
        RegisterComDll(DllPath, UnRegister)
    End If
End Sub

To unregister those Dlls, you set the UnRegister parameter to True.

ActiveX Edition

In addition to secman.dll and secman64.dll, the ActiveX edition of Security Manager provides 2 more files – osmax.ocx and osmax64.ocx.  To register them, just pass their full paths to the RegisterSecmanDll function above.

That’s all for now, in the next part I’ll show you how you can deploy your applications using the vsdrfCOMSelfReg option in standard setup projects created in Visual Studio.

You may also be interested in:

Outlook Security Manager deployment:.net, ActiveX and VCL basics, part 1
Outlook Security Manager deployment: self-registration in a Visual Studio setup project, part 3
Outlook Security Manager deployment: compiling a standalone application with "AnyCPU", part 4

Post a comment

Have any questions? Ask us right now!