<bdo id='w0J0L'></bdo><ul id='w0J0L'></ul>

    <i id='w0J0L'><tr id='w0J0L'><dt id='w0J0L'><q id='w0J0L'><span id='w0J0L'><b id='w0J0L'><form id='w0J0L'><ins id='w0J0L'></ins><ul id='w0J0L'></ul><sub id='w0J0L'></sub></form><legend id='w0J0L'></legend><bdo id='w0J0L'><pre id='w0J0L'><center id='w0J0L'></center></pre></bdo></b><th id='w0J0L'></th></span></q></dt></tr></i><div id='w0J0L'><tfoot id='w0J0L'></tfoot><dl id='w0J0L'><fieldset id='w0J0L'></fieldset></dl></div>

    <small id='w0J0L'></small><noframes id='w0J0L'>

      1. <legend id='w0J0L'><style id='w0J0L'><dir id='w0J0L'><q id='w0J0L'></q></dir></style></legend>
      2. <tfoot id='w0J0L'></tfoot>

        如何 UAC 使用 .NET 提升 COM 组件

        时间:2023-07-27
      3. <tfoot id='CNE4k'></tfoot>

              <tbody id='CNE4k'></tbody>
            <legend id='CNE4k'><style id='CNE4k'><dir id='CNE4k'><q id='CNE4k'></q></dir></style></legend>
            • <bdo id='CNE4k'></bdo><ul id='CNE4k'></ul>

              <small id='CNE4k'></small><noframes id='CNE4k'>

              • <i id='CNE4k'><tr id='CNE4k'><dt id='CNE4k'><q id='CNE4k'><span id='CNE4k'><b id='CNE4k'><form id='CNE4k'><ins id='CNE4k'></ins><ul id='CNE4k'></ul><sub id='CNE4k'></sub></form><legend id='CNE4k'></legend><bdo id='CNE4k'><pre id='CNE4k'><center id='CNE4k'></center></pre></bdo></b><th id='CNE4k'></th></span></q></dt></tr></i><div id='CNE4k'><tfoot id='CNE4k'></tfoot><dl id='CNE4k'><fieldset id='CNE4k'></fieldset></dl></div>

                1. 本文介绍了如何 UAC 使用 .NET 提升 COM 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我找到了一篇关于如何通过调用提升用 C++ 编写的 COM 对象的文章CoCreateInstanceAsAdmin.但是我无法找到或做的是一种将我的 .NET (c#) 应用程序的组件实现为 COM 对象然后调用该对象以执行需要 UAC 提升的任务的方法.MSDN 将其记录为 管理 COM 对象模型.

                  I've found an article on how to elevate a COM object written in C++ by calling CoCreateInstanceAsAdmin. But what I have not been able to find or do, is a way to implement a component of my .NET (c#) application as a COM object and then call into that object to execute the tasks which need UAC elevation. MSDN documents this as the admin COM object model.

                  我知道以管理员身份启动应用程序(或其他应用程序)是可能且非常容易的,以在单独的进程中执行任务(例如,参见 Daniel Moth 的帖子,但我正在寻找的是一种从在同一个未提升的 .NET 可执行文件中.这样做当然会在新进程中生成 COM 对象,但是由于透明编组,.NET COM 对象的调用者不应该(太多)知道它.

                  I am aware that it is possible and quite easy to launch the application (or another app) as an administrator, to execute the tasks in a separate process (see for instance the post from Daniel Moth, but what I am looking for is a way to do everything from within the same, un-elevated .NET executable. Doing so will, of course, spawn the COM object in a new process, but thanks to transparent marshalling, the caller of the .NET COM object should not be (too much) aware of it.

                  关于如何通过 CoCreateInstanceAsAdmin API 从 C# 项目中实例化用 C# 编写的 COM 对象的任何想法都会非常有帮助.所以我真的很想学习如何用 C# 编写一个 COM 对象,然后我可以通过 COM 提升 API 从 C# 调用它.

                  Any ideas as to how I could instanciate a COM object written in C#, from a C# project, through the CoCreateInstanceAsAdmin API would be very helpful. So I am really interested in learning how to write a COM object in C#, which I can then invoke from C# through the COM elevation APIs.

                  如果提升的 COM 对象不在同一个进程中运行,请不要介意.我只是不想启动整个应用程序.我只想提升将执行代码的 COM 对象.如果我可以写一些类似的东西:

                  Never mind if the elevated COM object does not run in the same process. I just don't want to have to launch the whole application elevated; I would just like to have the COM object which will execute the code be elevated. If I could write something along the lines:

                  // in a dedicated assembly, marked with the following attributes:
                  [assembly: ComVisible (true)]
                  [assembly: Guid ("....")]
                  
                  public class ElevatedClass
                  {
                      public void X() { /* do something */ }
                  }
                  

                  然后让我的主应用程序通过 CoCreateInstanceAsAdmin 调用来实例化 ElevatedClass.但也许我只是在做梦.

                  and then have my main application just instanciate ElevatedClass through the CoCreateInstanceAsAdmin call. But maybe I am just dreaming.

                  推荐答案

                  看Windows Vista UAC 演示示例代码

                  (您还需要 UnsafeNativeMethods.CoGetObject 的 Vista Bridge 示例方法)

                  (You also need the Vista Bridge sample for UnsafeNativeMethods.CoGetObject method)

                  C# 代码显示了几种不同的提升方式,包括 COM 对象

                  Which gives you C# code that shows a few different ways to elevate, including a COM object

                  (不完整的代码示例 - 获取上面的文件)

                  [return: MarshalAs(UnmanagedType.Interface)]
                  static internal object LaunchElevatedCOMObject(Guid Clsid, Guid InterfaceID)
                     {
                     string CLSID = Clsid.ToString("B"); // B formatting directive: returns {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 
                     string monikerName = "Elevation:Administrator!new:" + CLSID;
                  
                     NativeMethods.BIND_OPTS3 bo = new NativeMethods.BIND_OPTS3();
                     bo.cbStruct = (uint)Marshal.SizeOf(bo);
                     bo.hwnd = IntPtr.Zero;
                     bo.dwClassContext = (int)NativeMethods.CLSCTX.CLSCTX_ALL;
                  
                     object retVal = UnsafeNativeMethods.CoGetObject(monikerName, ref bo, InterfaceID);
                  
                     return (retVal);
                  }
                  

                  这篇关于如何 UAC 使用 .NET 提升 COM 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否有用于 Windows/C# 开发的可嵌入 Webkit 组件? 下一篇:从终结器调用 RCW 是否安全?

                  相关文章

                  1. <small id='gZmv6'></small><noframes id='gZmv6'>

                  2. <legend id='gZmv6'><style id='gZmv6'><dir id='gZmv6'><q id='gZmv6'></q></dir></style></legend><tfoot id='gZmv6'></tfoot>

                      <bdo id='gZmv6'></bdo><ul id='gZmv6'></ul>
                    <i id='gZmv6'><tr id='gZmv6'><dt id='gZmv6'><q id='gZmv6'><span id='gZmv6'><b id='gZmv6'><form id='gZmv6'><ins id='gZmv6'></ins><ul id='gZmv6'></ul><sub id='gZmv6'></sub></form><legend id='gZmv6'></legend><bdo id='gZmv6'><pre id='gZmv6'><center id='gZmv6'></center></pre></bdo></b><th id='gZmv6'></th></span></q></dt></tr></i><div id='gZmv6'><tfoot id='gZmv6'></tfoot><dl id='gZmv6'><fieldset id='gZmv6'></fieldset></dl></div>