Uninstalling an MS Office Application-Level VSTO Add-In

ms-officeuninstallationvsto

I am working on deploying my first Visual Studio Tools for Office (VSTO) add-in using VSTO 4.

There are some different options for installing the Add-In registry entries. It can be per user under HKEY_CURRENT_USER or per machine HKEY_LOCAL_MACHINE. A number of my users are running under Citrix or Terminal Services. I am in a situation where an administrator will be running my install on the server as the users do not have the correct rights. In addition, my users are only a small percentage of the users on these servers.

For those reasons I was planning on building a small utility that would ship with the Add-In. The utility would create the correct Per User registry keys to enable the add-in. The administrator would install the add-in dll and my utility to c:\program files*. Then the users who actually needed the add-in would be instructed to run the utility one time and click on the "Enable" button.

The problem I am stuck with now is how to uninstall the add-in. My un-installer (run again by an administrator) can deal with everything that it created but does not have a way to remove the Per User registry keys.

I was hoping this would be a problem and that Word would just ignore the missing Add-in on the next startup.

That does not work – Word reports an error trying to "install" the customization on the next run.

"Installing Office customization"
There was an error during
installation. Downloading file
file://xxx/xxx.vsto did not succeed.

I am including "|vstolocal" at the end of the registry entry per the Registry Entries for Application-Level Add-Ins msdn article.

Is there anyway to stop Word from trying to load the add-in if the file does not exist?
or
Is there a way for an uninstaller to clean up Per User registry entries on uninstall for a user other than the one running the uninstall?

I am doing my testing on a Windows 7 machine with Office 2007. I am using VSTO 4 targeting the .Net 4 Framework.

Best Answer

About your two questions

Is there anyway to stop Word from trying to load the add-in if the file does not exist?

Not that I'm aware of, but, I just tried moving off the DLL's the my reg entries point to for one of my addin's and I got no message (if I go into Word's options COM ADDins area, i can see the addin is not loaded, which would be correct).

Is there a way for an uninstaller to clean up Per User registry entries on uninstall for a user other than the one running the uninstall?

Nope, I'm virtually positive there is no way to do this. It'd require rights to EVERY user's Profile folders.

HOWEVER, you can create these weird keys under the Office reg tree, that essentially serve as "commands" for office apps to carry out when they load.

So on uninstall, you'd write the extra keys to the Office reg key that essentially says "remove these keys from the current HKCU hive when an office app loads".

Here's an example Reg script I found that shows the weird keys, but I can't right off find any links that document exactly what they are:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\AllUsersTemplates]
"Count"=dword:00000001
"Order"=dword:00000008

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\AllUsersTemplates\Create\Software\Microsoft\Office\12.0\Common\General]
"SharedTemplates"=hex(2):-fill in your own Binary Value-

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\RemoveInstantSearchBar]
"Count"=dword:00000001
"Order"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\RemoveInstantSearchBar\Create\Software\Microsoft\Office\12.0\Outlook\Search]
"DisableDownloadSearchPrompt"=dword:00000001

<<<<< CreateFile >>>>>>>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\FileCopy1]
"Count"=dword:00000001
"Order"=dword:00000008

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\User Settings\FileCopy1\CreateFile\FileCopy1.potx]
"TargetFile"="[AppDataFolder]\\Microsoft\\Templates\\FileCopy1.potx"
"SourceFile"="C:\\Documents and Settings\\All Users\\Templates\\FileCopy1.potx"

If you look closely, you'll see under the \Office\ key, a "user settings{name}\Create\" key and then the rest of the key path replicates the path from Software\ on down under HKCU.

You can use the keywords CREATE or DELETE (to remove a key).

Notice the COUNT and ORDER values though. Those are important and need to be set right.

But again, i can't find the links off hand that document this.

Related Topic