Reading GPO firewall policy using windows api

Pritesh Kadam 1 Reputation point
2022-11-01T05:21:06.08+00:00

Is there a way to read windows firewall policies from GPO using win32 API's?

I was trying to use GetGPOList() api but it fails with error 2148074274 . Which is an Active Directory replication error (REF https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/replication-error-2146893022) . I don't know what is causing this error .

But even if that api succeeds , I am not sure it will give access to firewall policy.

Here is my code for ref:

bool success = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);  
if (!success)  
{  
    printf("OpenProcessToken failed Error(%d)\n", GetLastError());  
    return;  
}  
else  
{  
    printf("OpenProcessToken success \n");  
}  

success = GetGPOList(hToken, NULL, NULL, NULL, GPO_LIST_FLAG_MACHINE, &pGPOList);  
if (success)  
{  
    //        Perform processing here.   
    while (pGPOList)  
    {  
        printf("%ls \n", pGPOList->lpDisplayName);  
    }  
    //        Free the GPO list when you finish processing.  
    FreeGPOList(pGPOList);  
}  
else  
{  
    printf("GetGPOList failed %lu\n", GetLastError());  
}  
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,734 questions
0 comments No comments
{count} votes