private static IRemoteWebConfigurationHostServer CreateRemoteObjectOn64BitPlatform(string server, string username, string domain, string password) { IRemoteWebConfigurationHostServer objectForIUnknown; MULTI_QI_X64[] amqi = new MULTI_QI_X64[1]; IntPtr zero = IntPtr.Zero; COAUTHINFO_X64 structure = null; IntPtr ptr = IntPtr.Zero; COSERVERINFO_X64 srv = null; Guid gUID = typeof(RemoteWebConfigurationHostServer).GUID; int errorCode = 0; COAUTHIDENTITY_X64 coauthidentity_x = null; IntPtr ptr3 = IntPtr.Zero; try { zero = Marshal.AllocCoTaskMem(0x10); Marshal.StructureToPtr(typeof(IRemoteWebConfigurationHostServer).GUID, zero, false); amqi[0] = new MULTI_QI_X64(zero); coauthidentity_x = new COAUTHIDENTITY_X64(username, domain, password); ptr3 = Marshal.AllocCoTaskMem(Marshal.SizeOf(coauthidentity_x)); Marshal.StructureToPtr(coauthidentity_x, ptr3, false); structure = new COAUTHINFO_X64(RpcAuthent.WinNT, RpcAuthor.None, null, RpcLevel.Default, RpcImpers.Impersonate, ptr3); ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure)); Marshal.StructureToPtr(structure, ptr, false); srv = new COSERVERINFO_X64(server, ptr); errorCode = System.Web.UnsafeNativeMethods.CoCreateInstanceEx(ref gUID, IntPtr.Zero, 0x10, srv, 1, amqi); if (errorCode == -2147221164) { throw new Exception(System.Web.SR.GetString("Make_sure_remote_server_is_enabled_for_config_access")); } if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } if (amqi[0].hr < 0) { Marshal.ThrowExceptionForHR(amqi[0].hr); } errorCode = System.Web.UnsafeNativeMethods.CoSetProxyBlanket(amqi[0].pItf, RpcAuthent.WinNT, RpcAuthor.None, null, RpcLevel.Default, RpcImpers.Impersonate, ptr3, 0); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } objectForIUnknown = (IRemoteWebConfigurationHostServer) Marshal.GetObjectForIUnknown(amqi[0].pItf); } finally { if (amqi[0].pItf != IntPtr.Zero) { Marshal.Release(amqi[0].pItf); amqi[0].pItf = IntPtr.Zero; } amqi[0].piid = IntPtr.Zero; if (ptr != IntPtr.Zero) { Marshal.DestroyStructure(ptr, typeof(COAUTHINFO_X64)); Marshal.FreeCoTaskMem(ptr); } if (ptr3 != IntPtr.Zero) { Marshal.DestroyStructure(ptr3, typeof(COAUTHIDENTITY_X64)); Marshal.FreeCoTaskMem(ptr3); } if (zero != IntPtr.Zero) { Marshal.FreeCoTaskMem(zero); } } return objectForIUnknown; }
private static IRemoteWebConfigurationHostServer CreateRemoteObjectOn64BitPlatform(string server, string username, string domain, string password) { IRemoteWebConfigurationHostServer objectForIUnknown; MULTI_QI_X64[] amqi = new MULTI_QI_X64[1]; IntPtr zero = IntPtr.Zero; COAUTHINFO_X64 structure = null; IntPtr ptr = IntPtr.Zero; COSERVERINFO_X64 srv = null; Guid gUID = typeof(RemoteWebConfigurationHostServer).GUID; int errorCode = 0; COAUTHIDENTITY_X64 coauthidentity_x = null; IntPtr ptr3 = IntPtr.Zero; try { zero = Marshal.AllocCoTaskMem(0x10); Marshal.StructureToPtr(typeof(IRemoteWebConfigurationHostServer).GUID, zero, false); amqi[0] = new MULTI_QI_X64(zero); coauthidentity_x = new COAUTHIDENTITY_X64(username, domain, password); ptr3 = Marshal.AllocCoTaskMem(Marshal.SizeOf(coauthidentity_x)); Marshal.StructureToPtr(coauthidentity_x, ptr3, false); structure = new COAUTHINFO_X64(RpcAuthent.WinNT, RpcAuthor.None, null, RpcLevel.Default, RpcImpers.Impersonate, ptr3); ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure)); Marshal.StructureToPtr(structure, ptr, false); srv = new COSERVERINFO_X64(server, ptr); errorCode = System.Web.UnsafeNativeMethods.CoCreateInstanceEx(ref gUID, IntPtr.Zero, 0x10, srv, 1, amqi); if (errorCode == -2147221164) { throw new Exception(System.Web.SR.GetString("Make_sure_remote_server_is_enabled_for_config_access")); } if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } if (amqi[0].hr < 0) { Marshal.ThrowExceptionForHR(amqi[0].hr); } errorCode = System.Web.UnsafeNativeMethods.CoSetProxyBlanket(amqi[0].pItf, RpcAuthent.WinNT, RpcAuthor.None, null, RpcLevel.Default, RpcImpers.Impersonate, ptr3, 0); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } objectForIUnknown = (IRemoteWebConfigurationHostServer)Marshal.GetObjectForIUnknown(amqi[0].pItf); } finally { if (amqi[0].pItf != IntPtr.Zero) { Marshal.Release(amqi[0].pItf); amqi[0].pItf = IntPtr.Zero; } amqi[0].piid = IntPtr.Zero; if (ptr != IntPtr.Zero) { Marshal.DestroyStructure(ptr, typeof(COAUTHINFO_X64)); Marshal.FreeCoTaskMem(ptr); } if (ptr3 != IntPtr.Zero) { Marshal.DestroyStructure(ptr3, typeof(COAUTHIDENTITY_X64)); Marshal.FreeCoTaskMem(ptr3); } if (zero != IntPtr.Zero) { Marshal.FreeCoTaskMem(zero); } } return(objectForIUnknown); }
private static IRemoteWebConfigurationHostServer CreateRemoteObjectOn64BitPlatform(string server, string username, string domain, string password) { MULTI_QI_X64[] amqi = new MULTI_QI_X64[1]; IntPtr guidbuf = IntPtr.Zero; COAUTHINFO_X64 ca = null; IntPtr captr = IntPtr.Zero; COSERVERINFO_X64 cs = null; Guid clsid = typeof(RemoteWebConfigurationHostServer).GUID; int hr = 0; COAUTHIDENTITY_X64 ci = null; IntPtr ciptr = IntPtr.Zero; try { guidbuf = Marshal.AllocCoTaskMem(16); Marshal.StructureToPtr(typeof(IRemoteWebConfigurationHostServer).GUID, guidbuf, false); amqi[0] = new MULTI_QI_X64(guidbuf); ci = new COAUTHIDENTITY_X64(username, domain, password); ciptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ci)); Marshal.StructureToPtr(ci, ciptr, false); ca = new COAUTHINFO_X64(RpcAuthent.WinNT, RpcAuthor.None, null, /*RpcLevel.Connect*/ RpcLevel.Default, RpcImpers.Impersonate, ciptr); captr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ca)); Marshal.StructureToPtr(ca, captr, false); cs = new COSERVERINFO_X64(server, captr); hr = UnsafeNativeMethods.CoCreateInstanceEx(ref clsid, IntPtr.Zero, (int)ClsCtx.RemoteServer, cs, 1, amqi); if ((uint)hr == 0x80040154) { throw new Exception(SR.GetString(SR.Make_sure_remote_server_is_enabled_for_config_access)); } if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } if (amqi[0].hr < 0) { Marshal.ThrowExceptionForHR(amqi[0].hr); } hr = UnsafeNativeMethods.CoSetProxyBlanket(amqi[0].pItf, RpcAuthent.WinNT, RpcAuthor.None, null, /*RpcLevel.Connect*/ RpcLevel.Default, RpcImpers.Impersonate, ciptr, 0); if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } return((IRemoteWebConfigurationHostServer)Marshal.GetObjectForIUnknown(amqi[0].pItf)); } finally { if (amqi[0].pItf != IntPtr.Zero) { Marshal.Release(amqi[0].pItf); amqi[0].pItf = IntPtr.Zero; } amqi[0].piid = IntPtr.Zero; if (captr != IntPtr.Zero) { Marshal.DestroyStructure(captr, typeof(COAUTHINFO_X64)); Marshal.FreeCoTaskMem(captr); } if (ciptr != IntPtr.Zero) { Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY_X64)); Marshal.FreeCoTaskMem(ciptr); } if (guidbuf != IntPtr.Zero) { Marshal.FreeCoTaskMem(guidbuf); } } }
private static IRemoteWebConfigurationHostServer CreateRemoteObjectOn64BitPlatform(string server, string username, string domain, string password) { MULTI_QI_X64[] amqi = new MULTI_QI_X64[1]; IntPtr guidbuf = IntPtr.Zero; COAUTHINFO_X64 ca = null; IntPtr captr = IntPtr.Zero; COSERVERINFO_X64 cs = null; Guid clsid = typeof(RemoteWebConfigurationHostServer).GUID; int hr = 0; COAUTHIDENTITY_X64 ci = null; IntPtr ciptr = IntPtr.Zero; try { guidbuf = Marshal.AllocCoTaskMem(16); Marshal.StructureToPtr(typeof(IRemoteWebConfigurationHostServer).GUID, guidbuf, false); amqi[0] = new MULTI_QI_X64(guidbuf); ci = new COAUTHIDENTITY_X64(username, domain, password); ciptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ci)); Marshal.StructureToPtr(ci, ciptr, false); ca = new COAUTHINFO_X64(RpcAuthent.WinNT, RpcAuthor.None, null, /*RpcLevel.Connect*/ RpcLevel.Default, RpcImpers.Impersonate, ciptr); captr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ca)); Marshal.StructureToPtr(ca, captr, false); cs = new COSERVERINFO_X64(server, captr); hr = UnsafeNativeMethods.CoCreateInstanceEx(ref clsid, IntPtr.Zero, (int)ClsCtx.RemoteServer, cs, 1, amqi); if ((uint)hr == 0x80040154) throw new Exception(SR.GetString(SR.Make_sure_remote_server_is_enabled_for_config_access)); if (hr < 0) Marshal.ThrowExceptionForHR(hr); if (amqi[0].hr < 0) Marshal.ThrowExceptionForHR(amqi[0].hr); hr = UnsafeNativeMethods.CoSetProxyBlanket(amqi[0].pItf, RpcAuthent.WinNT, RpcAuthor.None, null, /*RpcLevel.Connect*/ RpcLevel.Default, RpcImpers.Impersonate, ciptr, 0); if (hr < 0) Marshal.ThrowExceptionForHR(hr); return (IRemoteWebConfigurationHostServer)Marshal.GetObjectForIUnknown(amqi[0].pItf); } finally { if (amqi[0].pItf != IntPtr.Zero) { Marshal.Release(amqi[0].pItf); amqi[0].pItf = IntPtr.Zero; } amqi[0].piid = IntPtr.Zero; if (captr != IntPtr.Zero) { Marshal.DestroyStructure(captr, typeof(COAUTHINFO_X64)); Marshal.FreeCoTaskMem(captr); } if (ciptr != IntPtr.Zero) { Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY_X64)); Marshal.FreeCoTaskMem(ciptr); } if (guidbuf != IntPtr.Zero) Marshal.FreeCoTaskMem(guidbuf); } }