1
I have created this .bat-file which is invoked by clicking on the proper shortcut, which is configured properly. But the last two comparisons seem not to evaluate properly.
Here we go.
@ECHO off
SETLOCAL EnableDelayedExpansion
SET landevcename='Imagine any name for a device'
SET landevcestatus=0
SET landevcestatusDisab=0
SET landevcestatusConn=2
SET landevcestatusT="NONE"
SET landevceidx=0
SET counter=1
ECHO Lan device to be checked is: %landevcename%
FOR /F "tokens=1" %%I IN ('wmic PATH win32_networkadapter where "Name=%landevcename%" get index') DO (
IF !counter!==2 SET /a landevceidx=%%I
SET /a counter+=1
)
ECHO Index of local area connection is: %landevceidx%
SET /a counter=1
FOR /F "tokens=1" %%J IN ('wmic PATH win32_networkadapter where "Name=%landevcename%" get netconnectionstatus') DO (
IF !counter!==2 SET /a landevcestatus=%%J
SET /a counter+=1
)
ECHO Status of local area connection is: %landevcestatus%
REM IF %landevcestatus%==%landevcestatusDisab% SET /a landevcestatusT=Disabled
IF %landevcestatus%==0 SET /a %landevcestatusT% "ItIsNotEnabled"
REM IF %landevcestatus%==%landevcestatusConn% SET /a landevcestatusT=Connected
**IF %landevcestatus%==2 SET /a %landevcestatusT% "ItIsEnabled"**
ECHO Text - Status of local area connection is: %landevcestatusT%
ECHO Status of local area connection is: %landevcestatus%
CMD
@ECHO off
Those both:
IF %landevcestatus%==0 SET /a %landevcestatusT% "ItIsNotEnabled"
IF %landevcestatus%==2 SET /a %landevcestatusT% "ItIsEnabled"
Where could be the typo ?
Can you tell me the errors you are getting? – JohnnyVegas – 2016-03-02T14:23:00.470
ECHO Text - Status of local area connection is: %landevcestatusT% is NONE. – icbytes – 2016-03-02T14:24:03.627
Could you try setting an IF/ELSE rather than two separate FOR statements? It's seems a really complex routine for such a simple output. The problems are in the IF statements as it's only getting the variable you set at the start - ignoring everything else. – JohnnyVegas – 2016-03-02T14:41:48.203
You mean instead of two seperate if's ? not for's ? – icbytes – 2016-03-02T14:42:40.930