VBScript中的C#DLL,无需重装 [英] C# DLL from VBScript, no regasm

查看:105
本文介绍了VBScript中的C#DLL,无需重装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过 VBScript 访问C#DLL的方法而无需在 regasm 中注册它?我将创建DLL几乎使它对VBScript可见的任何奇特的要求,我都可以...

Is it possible to access a C# DLL's method from VBScript without registering it with regasm? I will be creating the DLL so pretty much any exotic requirement to make it visible to VBScript, I can do...

我已阅读在此处可能可以使用 GetObject VBScript 来实现这一点,但是我已经尝试了没有成功...除了使DLL COM可见之外,我还需要做其他事情吗? ?

I have read here that it might be possible to use GetObject from VBScript to achieve this, but I have tried that with no success... Is there anything else I need to do aside from making the DLL "COM visible" to make this work?

我需要避免 regasm 的原因是它需要管理员权限,因此我需要部署它DLL静默地发送给可能具有或不具有管理员权限的许多客户端。

The reason why I need to avoid regasm is that it requires admin rights, and I need to deploy this DLL "silently" to many clients that may or may not have admin rights.

推荐答案

否,必须注册,这是唯一的方法脚本解释器可以找到包含您在脚本的CreateObject()调用中使用的ProgId的DLL。带有清单的隔离COM不起作用,您不能为脚本解释器修改清单。

No, registration is required, the only way that the script interpreter can find the DLL that contains the ProgId that you use in the script's CreateObject() call. Isolated COM with a manifest doesn't work, you can't modify the manifest for the script interpreter.

有一个技术解决方案,您可以在HKCU注册表配置单元中写入注册表项,而无需获取UAC提升。 Regasm.exe工具始终将其写入HKLM配置单元中。这也将注册程序集,但仅适用于运行Regasm.exe的用户。但是,这非常痛苦且容易出错,您必须编写自己的注册方法并应用 [ComRegisterFunction]属性。现在,您要使用RegistryKey类来设置密钥。与[ComUnregisterFunction]相同,应该再次删除密钥。互联网上有很多错误的例子,最好的方法是使用SysInternals的ProcMon来观察正常使用Regasm.exe时写入的注册表项,然后重现该注册表项。

There is a technical solution, you can write registry keys in the HKCU registry hive without acquiring UAC elevation. The Regasm.exe tool always writes them in the HKLM hive. That registers the assembly as well, but only for the user that runs Regasm.exe. It is however pretty painful and easy to get wrong, you have to write your own registration method and apply the [ComRegisterFunction] attribute. It is now your job to use the RegistryKey class to set the keys. Same for the [ComUnregisterFunction], it should delete the keys again. There are a lot of bad examples out on the interwebs, best way to get this right is to use SysInternals' ProcMon to observe the registry keys that get written when you use Regasm.exe normally, then reproduce that in your own code, using HKCU instead.

请注意那枚奖章的另一面,实际上是在更改机器的配置,以允许运行任意代码。试图隐藏起来并不会给用户带来任何好处,如果您兑现了用户保持机器安全和可预测的愿望,那么就不应考虑这样做。 UAC并没有阻止您进行更改,它只是在通知用户。

Do note the other side of that medal, you are in fact making configuration changes to the machine that allows arbitrary code to run. Trying to hide that doesn't do the user any favors and should never be considered if you honor the user's desire to keep the machine safe and predictable. UAC is not there to stop you from making changes, it is only there to inform the user about it.

这篇关于VBScript中的C#DLL,无需重装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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