Question Locked

dos batch files

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello everyone,
I am working on batch files on windows xp. how can i make them to run on windows 2000. i am getting problem while running them on windows 2000.

7 replies

by bizzo

You'll need to be more specific with the problems you're having.

by thedrummer2006

A batch file is nothing more than a sequence of dos shell commands. Windows XP and 2000 have slightly different command sets available in their dos shells. You should open a dos shell and type help to see what commands are available.

by chris910

If you post the batch file we might be able to help. The syntax is a little different and XP has a few extra commands.

by aruna.jorige

Hello
I am giving a batch file which was running correctly on windows xp but not in windows 2000. could you tell me the differences i should make. i need the same output in both of the operating systems.

@echo off
set __COMPAT_LAYER=Win2000
setLocal EnableDelayedExpansion

if EXIST %temp%\temp.dat del %temp%\temp.dat
if EXIST %temp%\temp1.dat del %temp%\temp1.dat
if EXIST %temp%\temp2.dat del %temp%\temp2.dat

set user=NAC_%username%.txt

set x=0
set n=0
set m=0
set y=0

for /f "tokens=* delims= " %%k in ('ipconfig /all') do (
set /a x+=1
call :start %%k
if !y!==3 goto continue
if !y!==3 exit /B
)
goto end

:continue
set /a x=x+3
set val=!x!
for /f "skip=%val% tokens=1,* delims=:" %%a in ('ipconfig /all') do (
set str=%%a
set str=!str: =!
if "!str:~0,11!"=="Description" (
set /a n+=1
set NA!n!=%%b
)
if "!str:~0,8!"=="Physical" (
set /a m+=1
set PA!m!=%%b
)
)

echo.
set i=1
set j=1

echo. Physical Address NAC Address>>%temp%\temp1.dat
echo. --------------------------------------------------------------------->>%temp%\temp1.dat

:loop0
if !i! LEQ !n! (

echo !NA%i%!>%temp%\temp2.dat
for %%a in (%temp%\temp2.dat) do set /a length=%%~za
set /a length -=2
del %temp%\temp2.dat
set l1=!length!

if !j! LEQ !m! (

set /a maxlen=53-!l1!
set len=0
set string1=!NA%i%!

:cont
if !len! LSS !maxlen! (
set string1=!string1! &rem
set /a len+=1
goto cont
)

set string2=!PA%j%!
set string2=!string2:-=!
set /a i+=1
set /a j+=1
)
set "string1=%string1% %string2%"
echo. !string1!>>%temp%\temp1.dat
echo.
goto loop0
)
for /f "tokens=* delims= " %%a in (%temp%\temp1.dat) do echo. %%a
echo.
echo. Do you Want to save the result
echo.
set /p choice=(y/n)
if %choice%==y goto save
if %choice%==Y goto save
goto stop

:save
for /f "tokens=* delims= " %%a in (%temp%\temp1.dat) do echo. %%a>>!user!
echo.
echo. File is saved with the name !user! in the current folder
echo.
pause
:stop
if EXIST %temp%\temp.dat del %temp%\temp.dat
if EXIST %temp%\temp1.dat del %temp%\temp1.dat
if EXIST %temp%\temp2.dat del %temp%\temp2.dat

goto end

:start
if (%1)==() set /a y+=1
goto end

:end

by bizzo

Not sure why it's not working, but these changes will make it work on Windows 2000. (I'm testing on Windows 2000 Server SP4).

For some reason the counting in 2000 and XP seems to be different, maybe someone else can shed some light on that one. But in your ":continue" section, change 3 lines:
Change
set /a x=x+3
to
set /a x=x+2

Change
if "!str:~0,11!"=="Description" (
to
if "!str:~1,11!"=="Description" (

And change
if "!str:~0,8!"=="Physical" (
to
if "!str:~1,8!"=="Physical" (

This works on Windows 2000, but not on XP.

This discussion is closed to new replies.