Sample code for updating the Outlook account and store names following an SMTP address change


***

Update 03 Feb 2016 : Added code to allow changing the domain name only without having to connect to Active directory and code for narrowing down the processing to the default profile/account/store or just the default ones.

Usage: ProfileAccountUpdateTool [-?] [-ad] [-dc dcname] [-pm <1, 2 or 3>]
       [-am <0, 1 or 2] [-sm 1 or 2] [-od olddomainfqdn] [-nd newdomainfqdn]
       [-pn profilename]

Options:
       -ad:    Retrieve the new SMTP address from active directory.
       -dc:    Name of the Domain Controller to connect to. RootDSE used by default.
       -t:     AD timeout in seconds. Default value is 120 seconds.

       -od:    The FQDN of the old domain. For example: contoso.com.
       -nd:    The FQDN of the new domain. For example: northwindtraders.com.

       -pm:    Profile mode: 1 = default, 2 = all, 3 = specific.
       -pn:    Name of the profile to process. For example “Outlook”.
               The default profile will be used if no profile name is specified.
       -am:    Account mode: 1 = default, 2 = all.
       -sm:    Store mode: 1 = default, 2 = all.

       -?      Displays this usage information.

Examples:
       1)      Use AD to retrieve the primary SMTP address. Connect to CONTOSO_DC_01:
                   ProfileAccountUpdateTool -ad -dc CONTOSO_DC_01 -t 180
       2)      Specify the old and new SMTP domains and skip AD lookup
                   ProfileAccountUpdateTool -od contoso.com -nd talespintoys.com
       2)      Specify the old and new SMTP domains and skip AD lookup. Update all
               profiles, stores and accounts
                   ProfileAccountUpdateTool -od contoso.com -nd talespintoys.com -pm 2
                   -sm 2 -am 2

***

This is a follow up post for Outlook Code: Change the name of the root folder in Outlook 2010 after an SMTP address change.  Whilst the sample add-in that I’ve published at that time renamed the root folder in a simple and efficient way, it wasn’t possible to change the Account name, for which reason Outlook users were seeing their old SMTP address in the Mail From field in Outlook which seemed to cause a lot of confusion.  To address that, I have written a sample application that updates both the Account name and the root folder display name.

The sample uses Extended MAPI for logging on to the default profile and updating the default store display name (root folder), the Account Management API to access the default account and update the name and the Active Directory Service Interfaces to connect to Active Directory and retrieve the Primary SMTP address corresponding to the SMTP address set as the default account name.

I’m attaching both the code and the compiled executable below.

ProfileAccountUpdateTool.zip

Comments (3)

  1. Dmitry Streblechenko says:

    It looks like the zip file is empty 🙁

  2. SG says:

    What is the best trigger for this code?

    On system startup

  3. Andrei Ghita says:

    I'd say write a batch file or vbscript to run the exe and configure a Group Policy Object to run the script at logon.

    Here's a script example:

    Dim checkpoint, EXEPath

    EXEPath = WScript.Arguments.Item(0)

    Const HKEY_CLASSES_ROOT    = &H80000000

    Const HKEY_CURRENT_USER    = &H80000001

    Const HKEY_LOCAL_MACHINE   = &H80000002

    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\.rootdefault:StdRegProv")

    strKeyPath = "Outlook.ApplicationCurVer"

    strValueName = ""

    Dim oShell

    Set oShell = CreateObject("WScript.Shell")

    oReg.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, strValueName, strValue

    ' Wscript.Echo strValue

    if (strvalue = "Outlook.Application.15") Then

    Wscript.Echo "Office 15"

    oReg.GetStringValue HKEY_LOCAL_MACHINE, "SoftwareMicrosoftOffice15.0Outlook", "Bitness", Bitness

    If (Bitness = "x86") Then

    Wscript.Echo "It's 32 Bit"

    oReg.GetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", checkpoint

    If ((IsNull(checkpoint)) or (checkpoint = 0)) Then

          oShell.Run Chr(34) &  EXEPath  & "EXEName_x86.exe" & Chr(34)

        WScript.Sleep 5000

        oReg.SetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", 1

    End If

    Else

    Wscript.Echo "It's 64 Bit"

    oReg.GetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", checkpoint

    If ((IsNull(checkpoint)) or (checkpoint = 0)) Then

        oShell.Run Chr(34) &  EXEPath  & "EXEName_x64.exe" & Chr(34)

        WScript.Sleep 5000

        oReg.SetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", 1

    End If

    End If

    End If

    if (strvalue = "Outlook.Application.14") Then

    Wscript.Echo "Office 14"

    oReg.GetStringValue HKEY_LOCAL_MACHINE, "SoftwareMicrosoftOffice14.0Outlook", "Bitness", Bitness

    If (Bitness = "x86") Then

    Wscript.Echo "It's 32 Bit"

    oReg.GetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", checkpoint

    If ((IsNull(checkpoint)) or (checkpoint = 0)) Then

        oShell.Run Chr(34) &  EXEPath  & "EXEName_x86.exe" & Chr(34)

        WScript.Sleep 5000

        oReg.SetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", 1

    End If

    Else

    Wscript.Echo "It's 64 Bit"

    oReg.GetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", checkpoint

    If ((IsNull(checkpoint)) or (checkpoint = 0)) Then

            oShell.Run Chr(34) &  EXEPath  & "EXEName_x64.exe" & Chr(34)

        WScript.Sleep 5000

        oReg.SetDWORDValue HKEY_CURRENT_USER, "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles", "checkpoint", 1

    End If

    End If

    End If

Skip to main content