Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

Batch Files.bat

Jun 17, 2014 11:25PM PDT

Hi guys, I've been trying to make a simple batch file that will give you just the computer name, current user name, IPV4 address, The Default Gateway and the primary DNS server, I want these to be displayed on their own and not along with all the other crap, for example I wish for it to be displayed as the following:
Computer Name:
Current User:
IP address:
Default Gateway:
Primary DNS Server:

I have managed to do all of it apart from the Default Gateway, can anyone help please, there seems to be nowhere online with a valid answer to this that actually works...

Thanks Guys.

Discussion is locked

- Collapse -
Answer
Re: batch file
Jun 17, 2014 11:51PM PDT

The language for bartch execution in the command processor actually is rather limited. So I think it's very good that you manage to display all that other data. How did you do that?

Kees

- Collapse -
Batch Files.bat
Jun 18, 2014 1:32AM PDT

This is what I have got so far, with a space left out for the Default Gateway when I/If I get there eventually:

@ Echo Off
:B
Echo.
Echo What would you like to find?
Echo.
Echo DPS Information
Echo.
Echo.
Echo.
set /p input=Simply type DPS to proceed.
if %input%==DPS goto X

Love
cls
Echo.
Echo.
Echo.
Echo This section includes the following in order:
Echo.
Echo The Computer Name,
Echo.
Echo The Current User,
Echo.
Echo The Current IP Address,
Echo.
Echo The Current Default Gateway,
Echo.
Echo The Primary DNS Server
Echo.
Echo.
Echo.
Echo.
hostname
Echo.
whoami
Echo.
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
set ip=%ip:~1%
echo %ip%
Echo.

Echo.
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%
pause

- Collapse -
You might
Jun 18, 2014 9:52AM PDT

You might have slightly better luck if the batch file dumps the ipconfig output to a temp file, then read that file in so you know exactly which lines you want to extract out of it and can assign those to variables to output whenever appropriate. You can then have the batch file delete the temp file as the last operation before exiting so no one but you ever has to be the wiser that it ever existed.

Of course if you can use anything else, even Microsoft's PowerShell, you'd likely have a much easier go of things. Batch files are for what the name suggests: Batch operations. They have very limited functionality relative to almost any other programming language.

- Collapse -
(NT) no PAUSE used?
Jun 18, 2014 10:21AM PDT