Announcement

Collapse
No announcement yet.

IF, ELSE Batch file "frustrations"

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • IF, ELSE Batch file "frustrations"

    Hi,

    First of all apologies for any stupid basic errors in this small batch file.

    My problem is..
    When I execute the batch file below I always get the output of..

    =================
    Mis-match
    =================

    Even if I SET the varible to not be my actual computer name.. Please can someone let me know what I am doing wrong..


    ================================================== ======
    Code:
    @echo off
    
    SET /a variable=MyComputerName
    IF /I %computername%==%variable% %1 (
     goto Match 
       ) else ( 
      goto Mismatch 
        
    :Mismatch
    echo.                    
    echo.                        =================
    echo.                             Mis-match
    echo.                        =================
    goto :eof
    :Match
    echo.                    
    echo.                    =========================
    echo.                    .. Computer Name MATCH .. 
    echo.                    =========================
    goto :eof
    
    :eof
    echo end
    )
    ================================================== =====

    Many thanks,

    PeGo
    Last edited by Rems; 16th August 2011, 11:06. Reason: CODE-tags added

  • #2
    Re: IF, ELSE Batch file "frustrations"

    Code:
    @echo off
    
    SET "variable=%~1"
    IF /i "%computername%"=="%variable%" (
     goto :Match) else (goto :Mismatch)
    
    goto :end
    
    :Mismatch
    echo.                    
    echo.                        =================
    echo.                             Mis-match
    echo.                        =================
    
    goto :end
    
    :Match
    echo.                    
    echo.                    =========================
    echo.                    .. Computer Name MATCH .. 
    echo.                    =========================
    
    :end
    echo End...

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X