help with the bat file

August 25, 2010 at 06:44:41
Specs: Windows XP
@echo off

SET ARG=''

FOR /F "TOKENS=3 DELIMS= " %%A IN ('^(reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"\ ^|find "AltDefaultUserName"^) 2^>nul') DO (SET ARG=%%A)

echo %ARG%

if %ARG%=="eee" goto 1 else goto 2
:1
echo exist
goto end
:2
echo not exist

:end

I cant get this code to work it always says EXIST, any help would be great.


See More: help with the bat file

Report •

#1
August 25, 2010 at 07:45:27
I explain in the comments.


@echo off

rem to undefine a variable just put nothing after "="
SET ARG=


rem skip the header and request the rest of the
rem line in %%B on default delims (tab space
rem /v instead of "find"

FOR /F "skip=4 TOKENS=2* " %%A IN ('
    2^>NUL reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /V "AltDefaultUserName"
') DO (
    SET ARG=%%B
)

echo %ARG%


rem if you are going to compare with double
rem quotes (sometimes nessacery) then remember
rem batch INCLUDES the quotes in the comparison

rem if/else REQUIRES that at least the first
rem command be contained in brackets

rem the quotes meant that the condition was always
rem false and the lack of (brackets) meant
rem that else wasn't recognised. This caused the
rem code to always fall through.

if "%ARG%"=="eee" (goto 1) else goto 2


:1
echo exist
goto end
:2
echo not exist

:end
pause


Report •

#2
August 25, 2010 at 23:45:26
thanx, thanx, thanx, working great

Report •
Related Solutions


Ask Question