我试图以编程方式添加Windows 8' Metro'使用以下Microsoft提供的代码应用于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添加到例外列表中的问题。
有人可以提供有关如何使用此代码的任何示例吗?我真的输了!
答案 0 :(得分:0)
将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());
Here是一个复杂的使用示例。