You can get the "DHCP enabled" status of a network adapter by running the following command in your batch file:
FOR /F "tokens=2 delims=:" %%a IN ('netsh interface ip show addresses "Local Area Connection" ^| FIND "DHCP enabled"') DO ECHO %%a
where "Local Area Connection" is the name of the interface you're trying to set.
The options will be either "Yes" or "No", so you can query the status by using something like this:
SET _DHCP=FALSE
FOR /F "tokens=2 delims=:" %%a IN ('netsh interface ip show addresses "Local Area Connection" ^| FIND "DHCP enabled"') DO SET _DHCP=%%a
IF "%_DHCP%"=="FALSE" (
ECHO DHCP was not found for this interface. Please check the interface name.
) ELSE IF "%_DHCP%"=="Yes" (
ECHO DHCP is enabled
) ELSE (
ECHO DHCP is not enabled
)
This will query the DHCP status into an environment variable called _DHCP
. You will want to set _DHCP
to something such as FALSE
or NULL
before you query the status so that you will be able to know if the query failed.