HOW TO:Alter the "SetSecurity" and "Setup" project to support deployment of a VSTO Add-In for All Users


Why do we need to alter the "SetSecurity" and the "Setup" project? I sincerely suggest you read the following Blog posts and article first, otherwise you will not be able to make sense out of this post.


Deploying your VSTO Add-In to All Users (Part I)


Deploying your VSTO Add-In to All Users (Part II)


Automating the Deployment of Outlook Add-ins by Using Visual Studio Tools for Office Second Edition


Assuming you have gone through the articles above I will now walk you through the changes that need to be made in the "Setup" and the "SetSecurity" project. I am only targeting Office 2007 as of now.


Changes to the "Setup" project:


1) Set InstallAllUsers to TRUE.
2) Set the Version Number to the product’s version number.
3) Type your company name in the Manufacturer property.
4) The completed Registry on Target Machine setting for Office 2007 should look like below:


Registry Settings


Note: The name of the add-in will differ.


Changes to the "SetSecurity" project:


1) Alter the "Install" method to make sure the CAS policy is configured at the Machine level and not at the User Level. Replace the following line:


bool allUsers = String.Equals(allUsersString, "1");

with


bool allUsers = true;


Setting the "allUsers" variable to true makes sure that the CAS policy is created at the Machine level and NOT at the User level.


2) Add the following code to the CaspolSecurityPolicyCreator class in the CaspolSecurityPolicyCreator.cs


//Change the name of the Add-in to suit your needs
private const string userAppLocation = @"Software\Microsoft\Office\12.0\User Settings\OutlookAddIn1";

internal static void IncrementCounter()
{
RegistryKey instructionKey = null;
int count = 1;

try
{
instructionKey = Registry.LocalMachine.OpenSubKey(userAppLocation, true);
object value = instructionKey.GetValue("Count");

if (value != null)
{
if ((int)value != Int32.MaxValue)
count = (int)value + 1;
}
instructionKey.SetValue("Count", count);
}
finally
{
if (instructionKey != null)
instructionKey.Close();
}
}

internal static void RegisterDeleteInstruction()
{
RegistryKey instructionKey = null;
try
{
instructionKey = Registry.LocalMachine.OpenSubKey(userAppLocation, true);

if (instructionKey != null)
{
//Change the name of the Add-in to suit your needs
instructionKey.CreateSubKey(@"Delete\Software\Microsoft\Office\Outlook\AddIns\OutlookAddIn1");
}
}
finally
{
if (instructionKey != null)
instructionKey.Close();
}
}


3) Call the "IncrementCounter" method from the Install method.
4) Call the "IncrementCounter" and the "RegisterDeleteInstruction" methods from the Uninstall method.


That's all the changes that are needed. I have tried the setup on a Windows XP(Office 2007) machine and it WORKS!

Comments (0)

Skip to main content