2016-12-23 13 views
0

私はactiveXコントロールを作成しましたが、Internet Explorerに展開する際に問題が発生しています。ブラウザ(IE 11)はActiveXコントロールをダウンロードできません。何が間違っているのか、どのコードがうまく機能していないのかわかりません。私は.net 2010、フレームワーク4.0を使用していますc#.net windowsフォームでのActiveXコントロールの作成方法と展開方法

これは私が試みたコードです。

[ProgId("Newcomp.UserControl1")] 
[ClassInterface(ClassInterfaceType.AutoDual)] 
[Guid("5FE8E181-7D6D-4CE2-AB83-BAEB9906EF48")] 
[ComVisible(true)] 
public partial class UserControl1: UserControl 
{ 

    public UserControl1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     this.BackColor = Color.YellowGreen; 
    } 
    /// 
    /// Register the class as a control and set it's CodeBase entry 
    /// 
    /// The registry key of the control 
    [ComRegisterFunction()] 
    public static void RegisterClass(string key) 
    { 
     // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it 
     StringBuilder sb = new StringBuilder; 
     sb.Replace(@"HKEY_CLASSES_ROOT\", ""); 

     // Open the CLSID\{guid} key for write access 
     RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true); 

     // And create the 'Control' key - this allows it to show up in 
     // the ActiveX control container 
     RegistryKey ctrl = k.CreateSubKey("Control"); 
     ctrl.Close(); 

     // Next create the CodeBase entry - needed if not string named and GACced. 
     RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true); 
     inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase); 
     inprocServer32.Close(); 

     // Finally close the main key 
     k.Close(); 

    } 

    /// 
    /// Called to unregister the control 
    /// 
    /// Tke registry key 
    [ComUnregisterFunction()] 
    public static void UnregisterClass(string key) 
    { 
     StringBuilder sb = new StringBuilder; 
     sb.Replace(@"HKEY_CLASSES_ROOT\", ""); 

     // Open HKCR\CLSID\{guid} for write access 
     RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true); 

     // Delete the 'Control' key, but don't throw an exception if it does not exist 
     k.DeleteSubKey("Control", false); 

     // Next open up InprocServer32 
     RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true); 

     // And delete the CodeBase key, again not throwing if missing 
     k.DeleteSubKey("CodeBase", false); 

     // Finally close the main key 
     k.Close(); 
    } 
} 

は、私はあなたが経験している問題は、デフォルトでは、IE10(以降は)その中には、Active Xコントロールを実行します/あなたがダウンロードさせません、という事実によって引き起こされるthis

+1

これはあなたの質問に答えるのに役立つと思います。 http://stackoverflow.com/questions/26151999/ie11-prevents-activex-from-running – DaniDev

+1

また、残念ながら、あなたが従った例は2011年となっており、IE11の制限は予期していません。 – DaniDev

+0

@DaniDev - IE11で動作させるためにinorderで参照できる他のドキュメントはありますか? –

答えて

1

をも続いていますデフォルト設定。これはセキュリティ上の理由から行われました。つまり、ActiveXコントロールは悪意のある場所で使用されます。

残念なことに、「How To」記事(正確ではありますが):https://blogs.msdn.microsoft.com/asiatech/2011/12/05/how-to-develop-and-deploy-activex-control-in-c/、 は、このデフォルトの制限よりも前にユーザーに警告することを無視しています。

MicrosoftはIE10IE11にAciveXために、このフィルタを無効にする方法を提供します: https://support.microsoft.com/en-us/help/17469/windows-internet-explorer-use-activex-controls

このソリューションは、しかし、エンドユーザーによるアクションを必要とし、へのプログラマのための方法はありませんエンドユーザにアドバイスする以外に、このオプションを強制してください。これは、小さなオーディエンスのイントラネットアプリケーションでは機能しますが、より多くのオーディエンスにとっては扱いにくいものになります。

+0

巨大な量に達しなければならないので、アクティブなxコントロールの代わりにデスクトップアプリケーションを使うことに決めました。 –

関連する問題