How can I deploy a C # ActiveX object via a remotely loaded DLL (without pre-registration) using IE8 / IE9 and then access it using javascript?

I need to remotely load a .NET DLL containing an ActiveX object (non-visual) and then access it through javascript using the new ActiveXObject () method.

IE8 currently correctly loads this DLL using the path from the codebase attribute of the object tag, but ActiveXObject does not work because the ActiveX loader does not find the DLL in the registry.

I use ProcMon to track events that occur, and can check if the DLL is loading and that the registry is being examined by the new ActiveXObject method. this second part does not work, although the ActiveX object is not in the registry.

<body> <object name="Hello World" classid="clsid:E86A9038-368D-4e8f-B389-FDEF38935B2F" codebase="http://localhost/bin/Debug/Test.ActiveX.dll"> </object> <script type="text/javascript"> var hw = new ActiveXObject("Test.ActiveX.HelloWorld"); alert(hw.greeting()); </script> </body> 

If I use regasm , I can provide the necessary registrations, and then it all works, however I do not want to deploy the installer for this purpose. I understand that IE must register the DLL for me - I just don’t know Know what this does.

The .NET class has the necessary attributes to make all this work in regasm, but it seems the registry code is not being called. (Registration code was taken from here )

 namespace Test { [Guid("E86A9038-368D-4e8f-B389-FDEF38935B2F")] [InterfaceType(ComInterfaceType.InterfaceIsDual)] [ComVisible(true)] public interface IHelloWorld { [DispId(0)] string Greeting(); } [ComVisible(true)] [ProgId("Test.ActiveX.HelloWorld")] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(IHelloWorld))] public class HelloWorld : IHelloWorld { [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(key); sb.Replace(@"HKEY_CLASSES_ROOT\ ", ""); // <-- extra space to preserve prettify only.. not in the real code // Open the CLSID\{guid} key for write access using (RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true)) { // And create the 'Control' key - this allows it to show up in // the ActiveX control container using (RegistryKey ctrl = k.CreateSubKey("Control")) { ctrl.Close(); } // Next create the CodeBase entry - needed if not string named and GACced. using (RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true)) { inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase); inprocServer32.Close(); } // Finally close the main key k.Close(); } } ... public string Greeting() { return "Hello World from ActiveX"; } } } 
+4
source share
1 answer

The simple answer to this question is that you cannot; IE will not load an activex control that it does not know about.

What you can do is find a way to install the DLL (and thus register the ActiveX control), and then download it after installing it. Naturally, it is impossible to do this “automatically” without any prompts from the user, possibly because it will be night security holes.

Now, if you are just looking for a “native” installation method for an ActiveX control, it will be the CAB file that you specify. It will not do everything “automatically” for you, but it can be used to prompt IE to install the ActiveX control, which will launch your installer.

You can find information on how to use this method at http://msdn.microsoft.com/en-us/library/aa751974(v=vs.85).aspx

Doing what you are trying to do in C # is probably not a very flexible method; it will only work if the user has installed .net, and I never tried to use the CAB file to install the .net ActiveX control. I would recommend that you use a regular browser plugin or C ++ ActiveX control. You can look at FireBreath to create something in C ++ that will work as an ActiveX control, but also in all other browsers.

+2
source

Source: https://habr.com/ru/post/1336894/


All Articles