繁体   English   中英

以编程方式将应用程序添加到Windows 8 Loopback异常

[英]Programatically adding an application to Windows 8 Loopback exceptions

当尝试使用下面的Microsoft提供的代码将Windows 8“ Metro”应用程序以编程方式添加到Loopback例外列表时,我发现自己不胜枚举:

// Call this API to enumerate all of the AppContainers on the system 
[DllImport("FirewallAPI.dll")] 
internal static extern uint NetworkIsolationEnumAppContainers(out uint pdwCntPublicACs, out IntPtr ppACs); 

// Call this API to free the memory returned by the Enumeration API 
[DllImport("FirewallAPI.dll")] 
internal static extern void NetworkIsolationFreeAppContainers(IntPtr pACs); 

// Call this API to load the current list of Loopback-enabled AppContainers
[DllImport("FirewallAPI.dll")] 
internal static extern uint NetworkIsolationGetAppContainerConfig(out uint pdwCntACs, out IntPtr appContainerSids); 

// Call this API to set the Loopback-exemption list 
[DllImport("FirewallAPI.dll")]
internal static extern uint NetworkIsolationSetAppContainerConfig(uint pdwCntACs, SID_AND_ATTRIBUTES[] appContainerSids); 

// Use this API to convert a string SID into an actual SID 
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern bool ConvertStringSidToSid(string strSid, out IntPtr pSid); 

// Use this API to convert a string reference (e.g. "@{blah.pri?ms-resource://whatever}") into a plain string 
[DllImport("shlwapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)] 
internal static extern int SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, int cchOutBuf, IntPtr ppvReserved);

对于那些不了解Windows 8应用程序安全性的人,除非将“ Metro”应用程序添加到例外列表,否则不允许与localhost通信。 上面的代码(显然)有助于实现这一点,但是例如,我无法解决如何将Internet Explorer添加到例外列表中的问题。

有人可以提供有关如何使用此代码的示例吗? 我真的迷路了!

将Edge添加到异常的示例:

// We need construct PSID from this string sid
const string EDGE_SID = "S-1-15-2-3624051433-2125758914-1423191267-1740899205-1073925389-3782572162-737981194";
IntPtr pSid = IntPtr.Zero;
ConvertStringSidToSid(EDGE_SID, out pSid); // Pinvoked

List<SID_AND_ATTRIBUTES> list = PI_NetworkIsolationGetAppContainerConfig(); // For simplicity, this is borrowed from complex example below.

SID_AND_ATTRIBUTES item = new SID_AND_ATTRIBUTES(); // This Struct can be found in complex example too
item.Sid = sid;
list.Add(item);

uint r = NetworkIsolationSetAppContainerConfig((uint)list.Count, list.ToArray());

是用法的复杂示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM