Have a look at the key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
Under here are the adaptors defined on your system, and their settings.
To check if the address is in one of your ranges, use one of the many UDFs from the UDF forum.
You are currently checking to see if the service is running. AFAIK this service will normally always be running, even if the adaptor address is statically defined.
Finally, the entries may be persistent - you will have to explicitly remove the entries if you don't want to apply them, i.e.
code:
If DHCP_ASSIGNED_ADDRESS
ADD_PROXY_ENTRIES
Else
DELETE_PROXY_ENTRIES
EndIf
Consider adding a little debug code to display whether the proxy entries are being added or removed. It will help a lot in determining where the problem lies.