mercredi 27 juin 2018

Batch file check for multiple criteria for ipconfig | find /i statement

I've the following batch file to check the IP range the computer is in to decide whether or not the ABC.exe needs to be launched.

This works fine and since the first part of all 3 office locations share the same numbers at the beginning of their IP ranges up till the first number of the third octet (10.41.1) I'm currently just check for that.

@ECHO OFF
SET OFFICE_ALL=10.41.1
REM SET OFFICE_1=10.41.168.
REM SET OFFICE_2=10.41.162.
REM SET OFFICE_3=10.41.172.

REM SET VPN_CONNECTION=10.36.

ipconfig | find /i " %OFFICE_ALL%" >nul 2>nul && ( 
  start C:\ABC-tool\ABC.exe 
) || (
  exit
) 

That all said, we're going to move to a new location and the network colleagues told me that the IP range for the new office will become 10.44.121.x.

I've tried to adjust my script like this:

@ECHO OFF
SET OFFICE_MOST=10.41.1
REM SET OFFICE_1=10.41.168.
REM SET OFFICE_3=10.41.172.

SET OFFICE_2=10.44.121.

REM SET VPN_CONNECTION=10.36.

ipconfig | find /i " %OFFICE_MOST%" >nul 2>nul && ( 
  start C:\ABC-tool\ABC.exe 
) || ipconfig | find /i " %OFFICE_2%" >nul 2>nul && ( 
  start C:\ABC-tool\ABC.exe 
) || (
  exit
) 

But somehow that doesn't work... My understanding of the || is that the code after it only gets executed when the code prior to it wasn't successful, so it basically acts like an if-else construction. But apparently there is more to it and I can't figure it out. Where and why do I go wrong in my adjusted code?

Aucun commentaire:

Enregistrer un commentaire