以编程方式启用/禁用Outlook外接程序 [英] Enable/Disable Outlook Addin Programmatically

查看:173
本文介绍了以编程方式启用/禁用Outlook外接程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Outlook 2013创建了外接程序.

I have created Add-in for outlook 2013.

我想打开/关闭其他插件.所以我用下面的代码来做到这一点.

I wanted to on / off other addin. So I have used below code to do that.

Outlook.Application OutLook = new Outlook.Application();

if (OutLook.Application.COMAddIns.Item("OutlookAddIn").Connect)
{
 OutLook.Application.COMAddIns.Item("OutlookAddIn").Connect = false;
}
else
{
OutLook.Application.COMAddIns.Item("OutlookAddIn").Connect = true;
}

但是,只有当我以管理员身份打开Outlook时,它才能正常工作.对于普通用户,它不能正常工作.

But it is working fine, only if I open outlook as administrator. For normal user, it is not working fine.

那么我还有其他方法可以实现这一目标吗?或者我只能以管理员身份运行此代码?

So is there any other way I can achieve this? or I can run only this code as admin?

推荐答案

您必须是本地管理员或超级用户才能修改HKLM.普通用户没有足够的特权来修改 Windows注册表项用于加载项.很有可能该加载项已在HKLM配置单元中注册,对吗?

You need to be a local admin or a power user to be able to modify HKLM. A normal user doesn't have sufficient privileges for modifying the windows registry keys for the add-in. Most probably the add-in was registeredin the HKLM hive, am I right?

当然,对于每台计算机外接程序,如果您的应用程序是在具有管理权限的情况下运行的,则可以设置Connect属性.但是,在启用了UAC的系统上,除了具有管理权限之外,还必须提高应用程序的流程.

Of course, for a per-machine add-in, you can set the Connect property if your application is run with administrative permissions. But on a system with UAC enabled, in addition to having administrative permissions, the application process must be elevated.

您可以在Outlook中手动禁用加载项,甚至是每台计算机的加载项.这意味着您可以添加HKCU条目来完成它.如果我查看注册表,则HKEY_CURRENT_USER下Addin的'LoadBehavior'值已更改.但是HKEY_LOCAL_MACHINE下的'LoadBehavior'的值未更改.这是预期的行为-普通用户不能为所有用户禁用该插件.

You can disable the add-in manually in Outlook, even a per-machine add-in. It means that you can add a HKCU entry to get it done. If I look at the registry, the value of 'LoadBehavior' of the Addin under HKEY_CURRENT_USER has changed. But the value of 'LoadBehavior' under HKEY_LOCAL_MACHINE has not changed. This is expected behavior - normal user can't disable the Addin for all users.

请注意,在这种情况下,该加载项将仅对当前用户禁用.

Be aware, in that case the add-in will be disabled for the current user only.

这就是为什么我建议在运行时禁用外接程序的所有功能,而不是尝试将其关闭.在运行时,您可以检查用户是否被授权加载加载项,根据身份验证结果,您可以决定是否加载加载项的UI和其他业务逻辑(订阅Outlook事件等). . IE.该加载项将被启用,但最终用户不会注意到这一点.

That is why I'd suggest disabling all features of your add-in at runtime instead of trying to turn it off. At runtime you can check whether a user is authorized to load your add-in or not, based on the authentication results you can decide whether to load the add-in's UI and other business logic (subscribe to Outlook events and etc.) or not. I.e. the add-in will be enabled, but the end user will not notice that.

即使将LoadBehavior键添加到相应的HKCU配置单元中,该加载项也将在下次启动Outlook时加载.

Even if you add the LoadBehavior key to the corresponding HKCU hive, the add-in will be loaded next time Outlook is started.

这篇关于以编程方式启用/禁用Outlook外接程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆