Ipconfig doesn't work inside a bat file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Ipconfig doesn't work inside a bat file

#1 Post by Docfxit » 31 Mar 2019 14:43

When I run my batch file it shows me:

Code: Select all

                         IP INFORMATION
find: 'IP Address': No such file or directory
find: 'IPv4 Address': No such file or directory
find: 'Subnet Mask': No such file or directory
find: 'Default Gateway': No such file or directory
find: 'Host Name': No such file or directory
find: 'DNS Suffix Search List': No such file or directory
find: 'Physical Address': No such file or directory
find: 'DHCP Enabled': No such file or directory
find: 'DHCP Server': No such file or directory
Enter the ping options:
Running in Win7 32bit

This is my batch file:

Code: Select all

@echo.
@echo                          IP INFORMATION

@ipconfig /all | find "IP Address"
@ipconfig /all | find "IPv4 Address"
@ipconfig /all | find "Subnet Mask"
@ipconfig /all | find "Default Gateway"
@ipconfig /all | find "Host Name"
@ipconfig /all | find "DNS Suffix Search List"
@ipconfig /all | find "Physical Address"
@ipconfig /all | find "DHCP Enabled"
@ipconfig /all | find "DHCP Server"
@ping 127.0.0.1
@echo.
@pause
When I run it on a different computer (Also Win7) 64bit I get:

Code: Select all

                        IP INFORMATION
  IPv4 Address. . . . . . . . . . . : 192.168.168.9(Preferred)
  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . : 192.168.168.168
  Host Name . . . . . . . . . . . . : Docfxit
  Physical Address. . . . . . . . . : 0A-00-27-00-00-0E
  DHCP Enabled. . . . . . . . . . . : No

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
   Minimum = 0ms, Maximum = 0ms, Average = 0ms

Press any key to continue . . .
Both machines have C:\Windows\System32 in the path.
The Problem machine has an environment variable PATH:

Code: Select all

C:\Programs\cygwin\bin;C:\Programs\cygwin;C:\Programs\cygwin\usr\local\bin\perl\site\bin;C:\Programs\cygwin\usr\local\bin\perl\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0;C:\Program Files\ThinkPad\Bluetooth Software;C:\Program Files\Lenovo\Fingerprint Manager Pro;C:\Program Files\Intel\WiFi\bin;C:\Programs\Intel Management Engine Components\DAL;C:\Programs\Intel Management Engine Components\IPT;%SystemRoot%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Programs\Bitvise SSH Client;C:\Programs\Network Monitor 3\;C:\Program Files\HP\Digital Imaging\bin\Qt\Qt 4.3.3;C:\Programs\UltraEdit;C:\Programs\AudacitySoundConversionsox-14-4-2;%SystemRoot%\System32\WindowsPowerShell\v1.0\;C:\Programs\Client Access\Emulator;C:\Programs\Client Access\Shared;C:\Programs\Client Access\;C:\Program Files\Windows Imaging\;C:\Program Files\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Admin Arsenal\PDQ Deploy\;C:\Programs\PDQ Inventory\;C:\Program Files\Intel\UCRT\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\
The Problem machine also has an environment variable PATHEXT:

Code: Select all

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
On the problem machine if I add path to the bat file, It shows in the cmd window:

Code: Select all

C:\Dnload\9xAddons\Batch>path
PATH=C:\Programs\cygwin\bin;C:\Programs\cygwin;C:\Programs\cygwin\usr\local\bin\
perl\site\bin;C:\Programs\cygwin\usr\local\bin\perl\bin;C:\Program Files\Common
Files\Oracle\Java\javapath;C:\Program Files\Intel\Intel(R) Management Engine Com
ponents\iCLS\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Cl
ient\;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windo
ws\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Thi
nkPad\Bluetooth Software;C:\Program Files\Lenovo\Fingerprint Manager Pro;C:\Prog
ram Files\Intel\WiFi\bin;C:\Programs\Intel Management Engine Components\DAL;C:\P
rograms\Intel Management Engine Components\IPT;C:\Windows\System32\WindowsPowerS
hell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\
WirelessCommon;C:\Programs\Bitvise SSH Client;C:\Programs\Network Monitor 3\;C:\
Program Files\HP\Digital Imaging\bin\Qt\Qt 4.3.3;C:\Programs\UltraEdit;C:\Progra
ms\AudacitySoundConversionsox-14-4-2;C:\Windows\System32\WindowsPowerShell\v1.0\
;C:\Programs\Client Access\Emulator;C:\Programs\Client Access\Shared;C:\Programs
\Client Access\;C:\Program Files\Windows Imaging\;C:\Program Files\Windows Kits\
8.1\Windows Performance Toolkit\;C:\Program Files\Common Files\Intel\WirelessCom
mon\;C:\Program Files\Admin Arsenal\PDQ Deploy\;C:\Programs\PDQ Inventory\;C:\Pr
ogram Files\Intel\UCRT\;C:\Program Files\Intel\Intel(R) Management Engine Compon
ents\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Pro
gram Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C
:\Programs\Python\Python37-32\Scripts\;C:\Programs\Python\Python37-32\;C:\Progra
ms\Nmap;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\Wir
elessCommon\
If I add Dir /s ipconfig.exe into the bat file it shows:

Code: Select all

C:\>Dir /s ipconfig.exe
 Volume in drive C is Windows 7
 Volume Serial Number is 5CC2-21B0

 Directory of C:\Windows\System32

07/13/2009  06:14 PM            27,136 ipconfig.exe
               1 File(s)         27,136 bytes

 Directory of C:\Windows\winsxs\x86_microsoft-windows-ipconfig_31bf3856ad364e35_
6.1.7600.16385_none_4c104723794237c2

07/13/2009  06:14 PM            27,136 ipconfig.exe
               1 File(s)         27,136 bytes

     Total Files Listed:
               2 File(s)         54,272 bytes
               0 Dir(s)   2,689,814,528 bytes free
If I open a CMD prompt with or without (Run as Administrator) and run ipconfig /all it runs fine.

It has the same problem with the windows firewall turned on or not.
It has the same problem with my Antivirus turned on or not. Both machines have the same antivirus.
I have Windows Defender turned off.
Both machines are running with the same user with administrator privileges.

Does anyone have any idea why Ipconfig.exe doesn't pipe the output to the find correctly?

Thanks,
Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#2 Post by aGerman » 31 Mar 2019 17:35

Files are searched in the folders of the PATH variable in the same order as they appear in PATH. Since "C:\Programs\cygwin\bin" is the first search folder, find.exe in this folder has been called. Also the error message is that of the cygwin find.exe. That's not a problem of ipconfig.

Steffen

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#3 Post by Docfxit » 31 Mar 2019 20:06

You are a genius. That fixed the find immediately. I removed "C:\Programs\cygwin\bin" out of the environment path since it has it's own Environment entry.
Thank you very much for finding the fix for me.

You're great,

Thanks,
Docfxit

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#4 Post by Docfxit » 31 Mar 2019 20:11

On the bad computer this is what I am getting now:

Code: Select all

                         IP INFORMATION
   IPv4 Address. . . . . . . . . . . : 192.168.168.7(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.168.168
   Host Name . . . . . . . . . . . . : DocfxitLT
   Physical Address. . . . . . . . . : DC-53-60-08-29-56
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   DHCP Enabled. . . . . . . . . . . : No
Enter the ping options:
Which is exactly what I should be getting.

On the good computer this is what I am getting:

Code: Select all

                         IP INFORMATION
   IPv4 Address. . . . . . . . . . . : 192.168.168.9(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.168.168
   Host Name . . . . . . . . . . . . : Docfxit
   Physical Address. . . . . . . . . : 00-FF-C7-6F-04-FE
   DHCP Enabled. . . . . . . . . . . : No

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

Press any key to continue . . .
Do you have any idea why the ping isn't giving me the same results as the other computer?

Thanks,
Docfxit

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

Re: Ipconfig doesn't work inside a bat file

#5 Post by Squashman » 31 Mar 2019 20:27

Docfxit wrote:
31 Mar 2019 20:11

Do you have any idea why the ping isn't giving me the same results as the other computer?

Thanks,
Docfxit
Probably the same reason as why you were getting strange output from the FIND command. The windows ping command does not output what you are seeing on your screen.

Open up a command prompt to the same location you are executing your batch file from and type:

Code: Select all

where ping

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#6 Post by Docfxit » 31 Mar 2019 20:50

This is the output I get:

Code: Select all

C:\Users\MyUserName>where ping
C:\Windows\System32\PING.EXE
Thanks,
Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#7 Post by aGerman » 01 Apr 2019 07:42

Try to call ping.exe instead of only ping. Maybe there is also an executable script (such like ping.bat) somewhere in the current directory or in the PATH environment.

Steffen

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#8 Post by Docfxit » 01 Apr 2019 09:38

I changed it to Ping.exe. That didn't fix it. I noticed that machine has PROMPT=$P$G when I run SET in a cmd window. The other machine doesn't. I don't know if that might have something to do with it. I don't know where that comes from. It's not in the Environment Variables.

Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#9 Post by aGerman » 01 Apr 2019 09:54

That environment variable does only define how the cmd prompt looks like. $P$G is the default anyway.

Something else must have gone wrong. Run ...
SFC /SCANNOW
... from an elevated CMD window.

Steffen

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#10 Post by Docfxit » 01 Apr 2019 17:02

I did run SFC /scannow. It did find problems. I did reboot. I ran SFC /scannow again. I received:
Windows Resource Protection did not find any integrity violations.
I did re-boot.
I ran Winsock reset with:

Code: Select all

@Echo Off
netsh winsock reset catalog

netsh int ip reset resetlog.txt

ipconfig /release

ipconfig /flushdns

ipconfig /renew

ipconfig /registerdns
Echo .
Echo "Re-Input the Network IP Address After reboot"
Pause "Continuing will shutdown"

shutdown /r /t 00
cmd /k
I'm still getting the same error.

Thanks,
Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#11 Post by aGerman » 02 Apr 2019 04:32

The problem I have is that I didn't see the message "Enter the ping options:" before. I'm not even sure if you're facing the same problem like with find.exe because there are so many paths before C:\Windows\System32 in the PATH environment.

Things you still could try:
- Run ping with the fully qualified path. That is, C:\Windows\System32\ping.exe. If that works, try to move C:\Windows\System32 to the first place in the PATH environment. (Something that you could do anyway.)
- Run "info.bat". It's linked in the sticky post on top of the topic list in this forum. Maybe we find any hints, such as an AutoRun registry entry for the CMD. If the content is not a secret, copy\paste the text of the editor window that automatically opens.
- Run ping from within another CMD window. If that works, check your batch script in a HEX editor whether you saved it in a weird encoding or you have (not printable) characters that don't belong into a plain text script.

Steffen

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#12 Post by Docfxit » 02 Apr 2019 09:02

aGerman wrote:
02 Apr 2019 04:32
Things you still could try:
- Run ping with the fully qualified path. That is, C:\Windows\System32\ping.exe.
I have changed the bat file to this:

Code: Select all

@echo.
@echo                          IP INFORMATION

@ipconfig/all | find "IP Address"
@ipconfig/all | find "IPv4 Address"
@ipconfig/all | find "Subnet Mask"
@ipconfig/all | find "Default Gateway"
@ipconfig/all | find "Host Name"
@ipconfig/all | find "DNS Suffix Search List"
@ipconfig/all | find "Physical Address"
@ipconfig/all | find "DHCP Enabled"
@ipconfig/all | find "DHCP Server"
@C:\Windows\System32\PING.EXE 127.0.0.1
@echo.
@pause
It didn't fix the problem
aGerman wrote:
02 Apr 2019 04:32
If that works, try to move C:\Windows\System32 to the first place in the PATH environment. (Something that you could do anyway.)
I have changed the PATH environment putting C:\Windows\System32 to the beginning of the PATH
aGerman wrote:
02 Apr 2019 04:32
- Run "info.bat". It's linked in the sticky post on top of the topic list in this forum. Maybe we find any hints, such as an AutoRun registry entry for the CMD. If the content is not a secret, copy\paste the text of the editor window that automatically opens.
Please consider adding the text "info.bat" to the link above so a person could search for it on that page.

I have run "info.bat" on the computer that doesn't work:

Code: Select all

 INFO.BAT version 1.5
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 6.1.7601]
Product name           :  Windows 7 Ultimate, 64 bit
Performance indicators :  Processor Cores: 8      Visible RAM: 16703624 kilobytes

Date/Time format       :  (mm/dd/yy)  Tue 04/02/2019   7:31:34.08
__APPDIR__             :  C:\Windows\System32\
ComSpec                :  C:\Windows\System32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
Extensions             :  system: Enabled   user: Enabled 
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  04/01/2019  04:31 PM    17,104,510,976 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

                          Missing from the tool collection:  debug
I have run "info.bat" on the computer that does work:

Code: Select all

 INFO.BAT version 1.5
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 6.1.7601]
Product name           :  Windows 7 Ultimate, 32 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 2604844 kilobytes

Date/Time format       :  (mm/dd/yy)  Tue 04/02/2019   7:30:11.10
__APPDIR__             :  C:\Windows\system32\
ComSpec                :  C:\Windows\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Disabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  04/02/2019  07:05 AM     2,667,360,256 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

I noticed Extensions user: Disabled on the computer that does work.
I noticed Extensions user: Enabled on the computer that does not work.
aGerman wrote:
02 Apr 2019 04:32

- Run ping from within another CMD window. If that works, check your batch script in a HEX editor whether you saved it in a weird encoding or you have (not printable) characters that don't belong into a plain text script.

Steffen
Running this on both computers gives the same result:

Code: Select all

C:\Users\MyUser>ping 127.0.0.1

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
This has to have something to do with batch files for it to behave like it does.
When bringing up the bat file in a text editor it shows the code page is 1252 (ANSI - Latin I) on both computers.
I copied the bat file from the computer that does work to the computer that doesn't work. If there is a non text character in there it's the same on both computers. I do have pearl on the computer but I don't know how to search for a non text character.

Thank you for taking the time to look at this and comment on it.

Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#13 Post by aGerman » 02 Apr 2019 09:41

I noticed Extensions user: Disabled on the computer that does work.
Funny fact. I would have expected that's the machine which has problems to execute modern batch scripts. Things are a little screwed up on these computers as it seems to me :lol:

Try to write the code from scratch. (Or just copy it from your inital post, as it didn't contain weird characters when I pasted it in notepad.)
Even if I don't see any reason why that should be the culprit - it's quite unusual to prepend every line with an @. Try to begin the code with
@echo off
and remove the @ signs from the other lines.

Steffen

Docfxit
Posts: 130
Joined: 12 Nov 2015 12:42

Re: Ipconfig doesn't work inside a bat file

#14 Post by Docfxit » 02 Apr 2019 09:52

I changed it to this:

Code: Select all

@Echo Off
echo.
echo                          IP INFORMATION

ipconfig/all | find "IP Address"
ipconfig/all | find "IPv4 Address"
ipconfig/all | find "Subnet Mask"
ipconfig/all | find "Default Gateway"
ipconfig/all | find "Host Name"
ipconfig/all | find "DNS Suffix Search List"
ipconfig/all | find "Physical Address"
ipconfig/all | find "DHCP Enabled"
ipconfig/all | find "DHCP Server"
C:\Windows\System32\PING.EXE 127.0.0.1
echo.
pause
That didn't fix it.

Docfxit

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ipconfig doesn't work inside a bat file

#15 Post by aGerman » 02 Apr 2019 10:06

I'm afraid I'm at wit's end now :?

Post Reply