Stack Exchange
Grant a single program access while blocking all other programs (WFP)
Using Windows Filtering Platform i need to block all computer applications minus 1 especific aplication ?
Tried this code and does not work, it blocks all trafic :(
fwpFilter.layerKey = FWPM_LAYER_ALE_AUTH_CONNECT_V4;
fwpFilter.action.type = FWP_ACTION_BLOCK;
fwpFilter.subLayerKey = subLayerKey;
fwpFilter.weight.type = FWP_EMPTY; 
fwpFilter.numFilterConditions = 0; 
fwpFilter.displayData.name = GetWC("Block All APPS MINUS FIREFOX");
fwpFilter.displayData.description = GetWC("Block All APPS MINUS FIREFOX");

result = FwpmFilterAdd0(engine, &fwpFilter, NULL, NULL);

FWPM_FILTER_CONDITION0 Condition;
fwpFilter.layerKey = FWPM_LAYER_ALE_AUTH_CONNECT_V4;
fwpFilter.action.type = FWP_ACTION_PERMIT;
fwpFilter.weight.type = FWP_EMPTY;
fwpFilter.filterCondition = &Condition;
fwpFilter.numFilterConditions = 1;

PCWSTR appPath = (PCWSTR)GetWC("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FWP_BYTE_BLOB *fwpApplicationByteBlob;
fwpApplicationByteBlob = (FWP_BYTE_BLOB*)malloc(sizeof(FWP_BYTE_BLOB));
FwpmGetAppIdFromFileName0(appPath, &fwpApplicationByteBlob);

Condition.fieldKey = FWPM_CONDITION_ALE_APP_ID;
Condition.matchType = FWP_MATCH_EQUAL;
Condition.conditionValue.type = FWP_BYTE_BLOB_TYPE;
Condition.conditionValue.byteBlob = fwpApplicationByteBlob;

result = FwpmFilterAdd0(engine, &fwpFilter, NULL, NULL);

Thanks in advance

I see code but not useful error description. So what's the "problem"?

@user2864740 i already update the question with more details. The code works bue blocks all trafic, a i need that to allow one specific app to connect to the internet, only one, in this example : firefox.

Read through https://learn.microsoft.com/en-us/windows/desktop/fwp/filter-arbitration? "The only way for a filter to be bypassed is if a higher weight filter has permitted or blocked the traffic within the same sub-layer."; can check the final rules?

@user2864740 goog tip with the weight, but still not working >> full code here https://github.com/parxal/wfpfilter/blob/master/ConsoleApplication1/ConsoleApplication1.cpp

Find the error :: used FWPM_LAYER_ALE_FLOW_ESTABLISHED_V4 insted of FWPM_LAYER_ALE_AUTH_CONNECT_V4
