COM 互操作,无需 regasm

发布于 2024-08-03 07:17:34 字数 215 浏览 7 评论 0原文

我是一个受限用户,我需要编写一个在 Outlook 2003 和 2007 中公开 C# 库的 Outlook 宏。

我根本没有任何管理员权限,甚至在安装时也没有,所以我无法运行 RegAsm 和我无法(我假设)编写托管加载项。

在这种情况下有没有办法从VBA调用.Net代码,或者还有其他解决方案吗?

这仅供个人使用,因此丑陋的黑客攻击是完全可以接受的(只要它有效)

I'm a limited user, and I need to write an Outlook macro that exposes a C# library in Outlook 2003 and 2007.

I do not have any admin privilges at all, not even at install time, so I can't run RegAsm and I can't (I assume) write a managed add-in.

Is there any way to call .Net code from VBA in this scenario, or are there any other solutions?

This is for personal use only, so an ugly hack is perfectly acceptable (so long as it works)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

錯遇了你 2024-08-10 07:17:34

我通过使用 /regfile 选项运行 regasm 并在生成的 .reg 文件中用 HKCU 替换 HKLM 解决了这个问题。

I solved this by running regasm with the /regfile option, and replacing HKLM with HKCU in the resulting .reg file.

夜血缘 2024-08-10 07:17:34

RegistrationServices.RegisterAssembly .NET API(我相信 RegAsm.exe 使用它)。

还有 RegOverridePredefKey< /code>Win32 API,不起眼但非常有用,它允许将 HKEY_CLASSES_ROOT(由 RegisterAssembly 使用)重新映射到 HKEY_CURRENT_USER\Software\ClassesHKEY_CURRENT_USER\Software\Classes代码>.

聪明的程序可以使用 RegistrationServices.RegisterAssemblyRegOverridePredefKeyHKEY_CURRENT_USER 下为 COM 客户端注册程序集。

我自己还没有尝试过,但我相信这是完全可行的。

已更新,显然这种方法确实有效

There's RegistrationServices.RegisterAssembly .NET API (which I believe is used by RegAsm.exe).

There's also RegOverridePredefKey Win32 API, inconspicuous but quite useful, which allows to remap HKEY_CLASSES_ROOT (used by RegisterAssembly) to HKEY_CURRENT_USER\Software\Classes.

A clever program can use both RegistrationServices.RegisterAssembly and RegOverridePredefKey to register an assembly for COM clients under HKEY_CURRENT_USER.

I haven't tried this myself, but I believe it's quite doable.

Updated, apparently this approach does works.

红尘作伴 2024-08-10 07:17:34

注册 COM 对象(例如 ActiveX 控件)并使其对系统中的所有用户可见需要管理权限。

但是,如果不需要所有用户的可见性(或者由于有限的用户限制而不可能),则可以仅为特定用户注册 COM 对象。

这通常是通过在 HKCU 而不是 HKLM 中注册对象来完成的。这将适用于“常规”COM 对象和通过 .NET COM Interop 公开的对象。

还存在其他更细粒度的方法,例如已经提到的 RegFree COM,它可以处理特定的可执行文件。

因此,考虑到上述所有内容,将所有信息捕获到 reg 文件中并用 HKCU 替换 HKLM 的解决方案应该可以工作(不是很好,但工具也很好)。

Registering a COM object (ex. ActiveX control) and making it visible to all users in the system requires administrative rights.

BUT, if visibility to all users is not needed (or not possible due to limited user restriction) then the COM object can be registered only for the particular user.

This generally done by registering the object in HKCU instead of HKLM. This will apply for "regular" COM objects and the ones exposed through .NET COM Interop.

Other more fine grained approaches also exits, the already mentioned RegFree COM which addresses a particular executable.

So, given all of the above the solution to capture all info into reg file and replace HKLM with HKCU shall work (not nice, but so are the tools).

小草泠泠 2024-08-10 07:17:34

我发现了一个可能的 解决方案,但我还没有时间尝试。

I found a possible solution, but I haven't have time to try it yet.

缱绻入梦 2024-08-10 07:17:34

不幸的是,由于 COM 的工作方式,没有管理员权限就不可能安装 COM 对象(互操作或其他)。

当您注册 com 对象时,它会向 HKEY_CLASSES_ROOT 写入多个条目,这是一个机器级密钥,因此需要管理员权限。

现在,因为您确实说过黑客解决方案是可以接受的,所以您可以采取一些可能的步骤来使其发挥作用;但是,如果您没有管理员权限,我假设这不是您的计算机,并且很可能是工作计算机。采取这些步骤很可能会让你被解雇。标准免责声明之类的:如果你是个白痴并被起诉/解雇/枪杀/抢劫/等等,那不是我的错。

首先您需要找出需要添加哪些注册表项。确保您在一台“干净”的机器上执行此操作,该机器托管以前未见过的组件(或者您知道没有注册密钥的机器)。安装机器监控程序来捕获密钥。 此处是[不相关] MS 文章的链接,其中他们推荐了一些可以做到这一点的应用程序。

现在,随着监视器运行,安装您的插件。您现在应该能够获取需要创建哪些密钥的日志。使用您的日志创建注册表导出文件。

现在事情变得棘手了。基本上,您要做的就是从 BartPE 映像启动计算机并安装注册表并运行脚本;然而,关键路径将不正确,因此脚本将无法“开箱即用”。

MS 有一篇 TechNet 文章(但链接中有括号,因此在这里效果不佳),因此Google 一下,它应该是第一个结果。

阅读该文章后,您将看到计算机注册表将作为 HKEY_LOCAL_MACHINE 的子项安装。您需要做的是更改注册表导出以匹配新路径。此步骤完成后,您应该能够从 BartPE 映像启动,安装注册表,然后导入脚本,卸载配置单元,然后重新启动。假设您将文件复制到正确的路径,那么它“应该”可以工作。

祝你好运。

Unfortunately due to the way that COM works it would be impossible to install a COM object (interop or otherwise) without admin privileges.

When you register a com objects it writes several entries to HKEY_CLASSES_ROOT which is a machine level key and therefore requires admin privileges.

Now because you did say that a hackish solution is acceptable here are some possible steps you could take to get it to work; however if you do not have admin rights I am assuming that this is not your machine and most likely a work machine. Taking these steps could very well get you fired. Standard disclaimer and whatnot: It isn't my fault if you are a moron and get yourself sued/fired/shot/mugged/etc.

First you need to find out what registry keys need to be added. Make sure you are doing this on a 'clean' machine that host not seen your component before (or one you know that doesn't have the reg keys). Install a machine monitoring program to capture the keys. Here is a link to a [unrelated] MS article where they recommend some apps that do just that.

Now with the monitor running install you addin. You should now be able to get a log of what keys need to be created. Using your log create registry export files.

Now here is where it gets tricky. Basically what you will do is boot the machine from a BartPE image and mount the registry and run your scripts; however the key paths will be incorrect so the scripts will not work 'out of the box'.

MS has a TechNet article (but the link has parens in it so it doesn't play nice here) so Google it, it should be the first result.

After you have read that article you will see that the machines registry will be mounted as a subkey of HKEY_LOCAL_MACHINE. What you need to do is change your registry exports to match the new path. As soon as this step is complete you should be able to boot from your BartPE image, mount the registry, and then import your scripts, unmount the hive and then reboot. Assuming you copied the files to the correct path then it 'should' work.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文