简体   繁体   中英

Programatically adding an application to Windows 8 Loopback exceptions

I am finding myself out of my depth when trying to programatically add a Windows 8 'Metro' application to the Loopback exceptions list using the code provided by Microsoft below:

// 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);

For those unaware of the Windows 8 application security, 'Metro' apps are not allowed to communicate with localhost unless added to the exceptions list. The above code facilitates this (apparently), but I cannot work out for example how to add Internet Explorer to the exceptions list.

Can anybody provide any examples on how to use this code? I'm really lost!

Example adding Edge to exceptions:

// 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 is complex example of usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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