我在C#中创建了一个com组件,我使用Regasm注册了它。我现在可以使用ActiveXObject(...)在IE中使用它。但是,这仅在我更改IE安全设置并允许运行未签名的activex控件时才有效,在这种情况下,我收到消息:
此页面上的ActiveX控件可能不安全,无法与页面的其他部分进行交互。你想允许这种互动吗?
我总是希望IE在没有提示的情况下允许这种交互。有人知道如何做到这一点吗?
由于
答案 0 :(得分:5)
您的ActiveX控件必须实现IObjectSafety接口才能让IE停止显示“不安全”?提示。几年前我用VB6 ActiveX控件做了这个。在This page的第5步中展示了如何在.Net中完成。
答案 1 :(得分:3)
我已经遇到过这个问题。经过长时间的漫步,我已经解决了这个问题。在你的activeX类中只需继承IObjectSafety类。参见下图:
IObjectSafety类如下:
[ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
int GetInterfaceSafetyOptions(ref Guid riid,[MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions,[MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);
[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid,[MarshalAs(UnmanagedType.U4)] int dwOptionSetMask,[MarshalAs(UnmanagedType.U4)] int dwEnabledOptions);
}
public class IObjectSafetyImpl : IObjectSafety
{
private const string _IID_IDispatch = "{00020400-0000-0000-C000-000000000046}";
private const string _IID_IDispatchEx = "{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";
private const string _IID_IPersistStorage = "{0000010A-0000-0000-C000-000000000046}";
private const string _IID_IPersistStream = "{00000109-0000-0000-C000-000000000046}";
private const string _IID_IPersistPropertyBag = "{37D84F60-42CB-11CE-8135-00AA004BB851}";
private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
private const int _OK = 0;
private const int _FAIL = unchecked((int)0x80004005);
private const int _NOINTERFACE = unchecked((int)0x80004002);
private bool _fSafeForScripting = true;
private bool _fSafeForInitializing = true;
public int GetInterfaceSafetyOptions(ref Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions)
{
int Result = _FAIL;
string strGUID = riid.ToString("B");
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
switch (strGUID)
{
case _IID_IDispatch:
case _IID_IDispatchEx:
Result = _OK;
pdwEnabledOptions = 0;
if (_fSafeForScripting == true)
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
break;
case _IID_IPersistStorage:
case _IID_IPersistStream:
case _IID_IPersistPropertyBag:
Result = _OK;
pdwEnabledOptions = 0;
if (_fSafeForInitializing == true)
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
break;
default:
Result = _NOINTERFACE;
break;
}
return Result;
}
public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
{
int Result = _FAIL;
string strGUID = riid.ToString("B");
switch (strGUID)
{
case _IID_IDispatch:
case _IID_IDispatchEx:
if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_CALLER) &&
(_fSafeForScripting == true))
Result = _OK;
break;
case _IID_IPersistStorage:
case _IID_IPersistStream:
case _IID_IPersistPropertyBag:
if (((dwEnabledOptions & dwOptionSetMask) == INTERFACESAFE_FOR_UNTRUSTED_DATA) &&
(_fSafeForInitializing == true))
Result = _OK;
break;
default:
Result = _NOINTERFACE;
break;
}
return Result;
}
}
答案 2 :(得分:2)
您可以创建一个.reg文件来修改注册表项,如下所示:
Windows注册表编辑器版本5.00
[HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \ 0]
“1201”= DWORD:00000000
[HKEY_CURRENT_USER \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \ 0]
“1201”= DWORD:00000000
答案 3 :(得分:1)
- 开始 - >运行 - >注册表编辑器
- 转到 HKEY_CURRENT_USER \ SOFTWARE \微软\的Windows \ CurrentVer sion \ Internet Settings \ Zones \ 0
- Doubleclick 1201并将值更改为0(它是 可能1)
- 关闭注册表编辑器
醇>
答案 4 :(得分:0)
我认为您可以将网站信任级别设置为完整。
工具 - >网络选项 - >安全 - >可信网站 - >网站按钮
答案 5 :(得分:0)
至于签署ActiveX,请参阅this article。但是,您仍然必须允许ActiveX(它只会将您显示为作者)。请参阅Ryan关于如何允许此站点的ActiveX的答案。