In the end I decided not to bother with trying to P/Invoke WMI IPHelper functions. It was much easier to just kick-off a process opening cmd.exe and writing the console commands to add and remove route. The code below illustrates how this can be done.
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
CreateNoWindow = true
}
};
proc.Start();
proc.StandardInput.WriteLine(delete
? "route delete " + ServiceIpAddress + " mask " + GatewayMask + " " + GatewayIpAddress + " -p" : "route add " + ServiceIpAddress + " mask " + GatewayMask + " " + GatewayIpAddress + " -p");
roc.Close();