Recently I had to come up with a solution to the above dilemma, as it turns out enabling smart tags programmatically in outlook is quite the task. I was finally able to do it by modifying some registry keys for outlook, which are not that steight forward eaither. In essesnce its a two steps process:
1. Under “Current User” in the registry (regedit util), access “Software\Microsoft\Office\Common\Smart Tag\Applications\OpusApp” and insert a new binary value. The name of the new entry should be “LabelText” and its value should be “01 00 00 00″ or 64 in decimal.
2. This step is a bit trickier. We need to edit the Outlook default editor settings in the registry. For outlook 2007 the default editor is always Word. So find this key: “Software\Microsoft\Office\12.0\Word\Data” in the registry, we will need to edit the 334 and 519 bytes. When smart tags are enabled the 334 byte is incremented by 1 and the 519 byte is incremented by 128.
3. The whole process needs to be completed while outlook is not running.
Below is a sample consol app that enables smart tags for outlook.
static void Main(string[] args)
{
try
{
//Close Outlook
Process outlook = Process.GetProcessesByName("OUTLOOK").FirstOrDefault();
MessageBoxResult result = MessageBoxResult.Cancel;
if (outlook != null)
{
result = MessageBox.Show
(
"Outlook is running. Outlook will be closed for the installation to complete!",
"Outlook running",
MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation,
MessageBoxResult.OK
);
if (result == MessageBoxResult.OK)
{
if (!outlook.CloseMainWindow())
{
outlook.Kill();
}
outlook.WaitForExit();
}
else
{
throw new Exception("HEI Smart Tags Installation failed because Outlook is running. Close Outook and try to install again.");
}
}
if (result == MessageBoxResult.OK)
{
outlook = new Process();
outlook.StartInfo = new ProcessStartInfo("OUTLOOK");
outlook.Start();
}
EnableSmartTags();
}
catch (Exception ee)
{
#if DEBUG
Console.Write(ee);
#endif
}
}
private static void EnableSmartTags()
{
RegistryKey word = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Common\Smart Tag\Applications\OpusApp", true);
if (word == null)
{
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Office\Common\Smart Tag\Applications\OpusApp");
word = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Common\Smart Tag\Applications\OpusApp", true);
}
bool isSmartTagEnabled = word.GetValue("LabelText") == null;
word.SetValue("LabelText", new byte[4] { 1, 0, 0, 0 }, RegistryValueKind.Binary);
word.Close();
///To Properly enable smart tags in Outlook, couple of bytes need to be set to a specific value
///The key location is:Software\Microsoft\Office\12.0\Word\Data\fs
///and the value entry is:SettingsWordMail
///In the byte array
///the 334 byte needs to be incremented by 1 to enable smart tags and
///the 519 byte needs to be incremented by 128 to enable smart tags
///double check not to overflow the 519 byte.
RegistryKey worddata = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\12.0\Word\Data", true);
if (worddata != null)
{
byte[] wordEmailSettings = worddata.GetValue("SettingsWordMail") as byte[];
//Outlook
if (!isSmartTagEnabled)
{
//Check if the bit will overflow
if (wordEmailSettings[519] < = 128)
{
//This byte should not be incremented if the second byte is not updated
wordEmailSettings[334] += 1;
wordEmailSettings[519] += 128;
}
}
//Outlook
worddata.SetValue("SettingsWordMail", wordEmailSettings, worddata.GetValueKind("SettingsWordMail"));
worddata.Close();
}
Hopefully this little hack will save someone else some time and effort out there.