Access was denied during "FlushIpNetTable" call, despite elevated privileges

  arp, c++, winapi, windows

the code compiles correctly, but although I run the code with elevated privileges, I still have access denied.

I run the program like this: runas.exe / user: "admin" FlushIpNetTable.exe

OS: Windows 10 Version 10.0.10240

Does anyone have any suggestions why, despite the increased privileges, I cannot clean this table? 🙂 ?

#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "IPHLPAPI.lib")


int main() {

    DWORD res, dwIndex;
    dwIndex=2;
    res = FlushIpNetTable(dwIndex);

    if (res == ERROR_ACCESS_DENIED) {
        printf("Access is denied.n");
        getchar();
        exit(1);
    } else if (res == ERROR_INVALID_PARAMETER) {
        printf("An input parameter is invalid, no action was taken.n");
        getchar();
        exit(1);
    } else if (res == ERROR_NOT_SUPPORTED) {
        printf("The IPv4 transport is not configured on the local computer.n");
        getchar();
        exit(1);
    }else {
        printf("Use FormatMessage to obtain the message string for the returned error.n");
        getchar();
        exit(1);
    }
    return 0;
}

Source: Windows Questions

LEAVE A COMMENT