Cannot get a bat file to work in Windows XP

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
eXtremer
Posts: 3
Joined: 11 Mar 2015 11:28

Cannot get a bat file to work in Windows XP

#1 Post by eXtremer » 11 Mar 2015 11:50

I've got some user that still use Windows XP, for them I made this code below, because at that moment I didn't had a Windows XP machine I've mad the testings on a Windows Server 2003, the code worked without an issue, now when trying the same code on a Windows XP machine unfortunately it doesn't work.

The code:

Code: Select all

@rasdial VPN username password
@setlocal
@for /f "tokens=1-2 delims=:" %%i in ('ipconfig ^| find "IP Address" ^| find "172.23"') do set GETIP=%%j
@route add 172.30.255.0 mask 255.255.255.0 %GetIp%
@endlocal


Host: 172.30.255.22
Gateway: might be any IP in this range 172.23.241.2-172.23.241.2 given by the DHCP server

That's why I need to know IP of the gateway before adding a route, in Windows 7 is much more simple to do it, but XP gives me headaches!

Thank you.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cannot get a bat file to work in Windows XP

#2 Post by Squashman » 11 Mar 2015 12:41

I fail to see how you are getting the Gateway IP address with that code.

eXtremer
Posts: 3
Joined: 11 Mar 2015 11:28

Re: Cannot get a bat file to work in Windows XP

#3 Post by eXtremer » 11 Mar 2015 12:45

Squashman wrote:I fail to see how you are getting the Gateway IP address with that code.


Can you help me with this one? Thank you.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cannot get a bat file to work in Windows XP

#4 Post by Squashman » 11 Mar 2015 12:57

If you are trying ascertain the Default Gateway shouldn't the FIND be searching for Default Gateway?

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Cannot get a bat file to work in Windows XP

#5 Post by Matt Williamson » 13 Mar 2015 08:57

Here
Try this:

Code: Select all

@echo off
setlocal

call :wmic nicconfig where "IPEnabled=TRUE and IPConnectionMetric>0" get defaultipgateway /format:list
exit /b

:wmic
for /f "delims=" %%A in ('wmic %*') do for /f "delims=" %%B in ("%%A") do (
   for /f "tokens=2 delims==" %%a in ("%%B") do (
      if /i %%a NEQ "" (
         for /f delims^=^"^ tokens^=2 %%b in ("%%a") do (echo %%b)
      )   
   )
)   
exit /b

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cannot get a bat file to work in Windows XP

#6 Post by Squashman » 13 Mar 2015 10:05

Matt, Will not work for XP Home.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Cannot get a bat file to work in Windows XP

#7 Post by Matt Williamson » 13 Mar 2015 11:06

I know but he's working in a producton environment so WinXP pro is just an assumption. If he does need it for xp home, I have another script using ipconfig instead.

eXtremer
Posts: 3
Joined: 11 Mar 2015 11:28

Re: Cannot get a bat file to work in Windows XP

#8 Post by eXtremer » 15 Mar 2015 03:23

Matt Williamson wrote:I have another script using ipconfig instead.


Can you post please? Thank you.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Cannot get a bat file to work in Windows XP

#9 Post by Compo » 15 Mar 2015 06:48

What is the output when this is run on the XP Unit(s)?

Code: Select all

@Echo Off
SetLocal
For /F "Tokens=1*" %%A In (
   'IPConfig^|FindStr "\<[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\>"') Do Call :Sub %%B
Set _
Pause
Exit/B
   :Sub
   Set _=%*
   For /F "Tokens=1-2 Delims=: " %%A in ("%_:. =%") Do Set "_%%A=%%B"
   Set "_="

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cannot get a bat file to work in Windows XP

#10 Post by Squashman » 15 Mar 2015 10:24

eXtremer wrote:
Matt Williamson wrote:I have another script using ipconfig instead.


Can you post please? Thank you.

What did you not understand about my last question that you did not answer?

Post Reply