1.

Solve : IPconfiguration script working on Windows 7 but not XP...?

Answer»

Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scripting, so im gonna post it right away, so the main problem that is i needed a script which shows the active network adapters, then lists them gives'em ID so a user can enter the ID and then get's asked for what kind of a setup he wants, DHCP y/n, then if DHCP it configures adapter X for dhcp if not runs a next question and lists all bat files(profiles) in the same directory except the one running now. so the thing is IT works on Windows 7... what i need is a fix for it, or a XP revision so it works under XP sp3

the script
Code: [Select]@ECHO OFF
ECHO.
ECHO Choose the interface (input the id):
ECHO.
setlocal EnableDelayedExpansion
FOR /F "tokens=1,5,*" %%A IN ('netsh int ipv4 show interfaces') DO (
SET initString=%%A
REM These next three lines just format the output table nicely,
REM they will be explained later.
call :strlen resLen !initString!
call :getNiceString resultString !resLen! 5 !initString!
ECHO !resultString! %%B %%C
)
ECHO.
set /P INTID=Type interface ID: %=%
ECHO.
ECHO Do you want DHCP? (y/n)
ECHO.
set /P answer=Type answer: %=%
ECHO.

if "%answer%"=="y" (

REM configure IP and DNS for the given DHCP
netsh int ipv4 set address %intID% dhcp
netsh int ipv4 set dns %intID% dhcp
) ELSE (
ECHO Choose your configuration file:
set /a var=1
REM list the files in the directory which contain ".bat" in their names
REM and save them in an array (there are no arrays in batch scripting), explained later.
FOR /F %%F IN ('DIR /B /oN^|FIND /i ".bat"') DO (
REM check that the file being listed is not the running file
if /I "%%F" NEQ "%~nx0" (
set __Files.!var! = %%F
ECHO !var! - %%F
set /a var = !var!+1
)
)
ECHO.
REM Ask for the file number
set /P file=Type file number: %=%
ECHO.

REM this might seem confusing at first. The SET __Files.X command
REM where X is a number, returns a line similar to this:
REM __Files.X = some_value. And because "some_value" is what matters,
REM we need to split that line in two tokens. How to do it:
FOR /F "tokens=2* delims=.=" %%A IN ('SET __Files.!file!') DO (
ECHO Starting profile %%B
START %%B %intID%
ECHO Profile %%B succesfully started.
)
)
endlocal
pause
goto :eof

REM the following portion of code is here just to print things nicely
REM gets the necessary number of spaces to add to a string and returns
REM the value in the first parameter.
:getNiceString <resultString> <strLength> <resultLength> <initString>
(
set /a diff = %~3 - %~2
set resString=%~4
FOR /L %%i in (1,1,!diff!) DO (
REM note the space at the end of the following line
set resString=!resString!
REM right here ^
)
set "%~1=!resString!"
exit /b
)

REM gets the LENGTH of a string VARIABLE
:strlen <resultVar> <stringVar>
(
set string=%~2
set len=0
:loop
if "!string!" NEQ "" (
set string=!string:~1!
set /a len=!len!+1
goto loop
)
)
(
set "%~1=%len%"
exit /b
)
taken from http://ricardo.szyfer.com/I would go through and test the different commands that you USE on XP. That way you will know exactly what part of the program is causing the error. Then you can look into checking up on what the command does, and if there is a different command that is XP compatible that you COULD use.

I would start with the odd ones like netsh.


You could also add pauses between the different blocks. Then run and count how many pauses happen before the crash. This will help you to narrow the error down to a single line or for loop.Quote from: tixed on May 16, 2013, 11:56:20 AM

Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scripting
Define a lot. I belong to at least 6 forums that all support batch scripting.Quote from: tixed on May 16, 2013, 11:56:20 AM
taken from http://ricardo.szyfer.com/
Nice that he took the time to write that but there are plenty of free programs out there that will run in the task tray and you can setup predefined network profiles and switch to one with two mouse clicks.
http://www.snapfiles.com/get/netsetman.htmlXP doesn't support the Netsh command which is the first external file used.

Code: [Select]c:\XP Box>netsh int ipv4 show interfaces
The following command was not found: int ipv4 show interfaces.
okay, im no expert in BATCH scripting, and the author tried to fix it but, as we know many infrastructures still use XP, so im still diging thru, and yes im trying to post everywhere i know, so maybe someone has a global idea how to solve this FOR XP.
Quote from: Squashman on May 16, 2013, 07:00:39 PM
Define a lot. I belong to at least 6 forums that all support batch scripting.

Some time before there were even 3 forums in my native language, now everyone is obsessed with newer win versions...

Now im thinking maybe this can be done for both WinXP and Win7 through VBscript call ?


Discussion

No Comment Found