Пример #1
0
 internal static extern object CoGetObject(
     string pszName,
     [In] ref SafeNativeMethods.BIND_OPTS3 pBindOptions,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
        static internal object LaunchElevatedCOMObject(Guid Clsid, Guid InterfaceID)
        {
            // B formatting directive: returns 
            // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.
            string CLSID = Clsid.ToString("B");  
            string monikerName = "Elevation:Administrator!new:" + CLSID;

            SafeNativeMethods.BIND_OPTS3 bo = new SafeNativeMethods.BIND_OPTS3();
            bo.cbStruct = (uint)Marshal.SizeOf(bo);
            bo.hwnd = IntPtr.Zero;
            bo.dwClassContext = (int)SafeNativeMethods.CLSCTX.CLSCTX_ALL;

            object retVal = UnsafeNativeMethods.CoGetObject(
                monikerName, 
                ref bo, 
                InterfaceID);

            return (retVal);
        }