Need to make a better batch file

M

Mygposts

I need a batch file that a user can click on and have it display their user
name, machine name and ip addresses for that machine.

I should display a command window displaying:

I am logged on as XXX
My computer name is XXX
My IP addresses are XXXXXXXX, XXXXXXX

I have one that works, but it displays the ipconfig commands and adds clutter.

ipconfig | FIND /I "ip address"

@echo I am logged in as %username%. My computer name is %computername%.


pause


How can this be cleaned up so they see "My IP address is (ip address)"
instead of ipconfig | FIND /I "ip address"
 
A

Anteaus

Trying to do this kind of thing with a batch file is kinda stretching its
capabilities.

Definitely a task for AutoIt.
http://autoitscript.com
or maybe VBScript. But AutoIt wins in terms of its GUI capability.
 
G

Guest

In VBS it's easy to do

Batch files are Pegasus' area. My batch programming is 15 or more years ago

Why does it need to be a batch file
 
P

Pegasus [MVP]

SPAMCOP User said:
In VBS it's easy to do

Batch files are Pegasus' area. My batch programming is 15 or more years
ago

Why does it need to be a batch file

How can I resist such a galant invitation? Here you go:
@echo off
echo\
echo I am logged on as %UserName%.
echo My computer's name is %ComputerName%.
echo My IP settings are
ipconfig | find "." | find /i /v "suffix"
echo\
echo Press the Space bar to close this window.
pause > nul

If you want something a little more upmarket then this VB Script file should
fit the bill. You must unwrap any lines that your newsreader has wrapped
around, then remove the line numbers and save it as c:\xyz.vbs. You then
invoke it with this command:
wscript c:\xyz.vbs

[01] Set oWshShell = CreateObject("WScript.Shell")
[02] Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
[03] Set colNetAdapters = oWMIService.ExecQuery _
[04] ("Select * from Win32_NetworkAdapterConfiguration Where
IPEnabled=True")
[05] MacAddress = ""
[06] LF = Chr(10)
[07]
[08] For Each oNetAdapter In colNetAdapters
[09] If MacAddress = oNetAdapter.MACAddress then Exit For
[10] MacAddress = oNetAdapter.MACAddress
[11] sLine = oWshShell.ExpandEnvironmentStrings("User Name: %UserName%") &
LF _
[12] & oWshShell.ExpandEnvironmentStrings("Computer Name: %ComputerName%")
& LF _
[13] & "MAC Address: " & oNetAdapter.MACAddress & LF _
[14] & "DHCP Enabled: " & oNetAdapter.DHCPEnabled & LF _
[15] & Compile("IP Address",oNetAdapter.IPAddress) & LF _
[16] & Compile("Default Gateway", oNetAdapter.DefaultIPGateway) & LF _
[17] & Compile("Subnet Mask", oNetAdapter.IPSubnet) & LF _
[18] ' & Compile("DNS_Server", oNetAdapter.DNSServerSearchOrder) & LF
[19] Next
[20] MsgBox sLine, 0, "Status Report"
[21]
[22] Function Compile(Subject, Details)
[23] If IsArray(Details) Then
[24] For i = 0 To UBound(Details)
[25] Line = Subject & ": " & Details(i)
[26] Next
[27] Else
[28] Line = Subject & ": " & Details
[29] End If
[30] Compile = Line
[31] End Function
 
P

Pegasus [MVP]

Mygposts said:
I need a batch file that a user can click on and have it display their user
name, machine name and ip addresses for that machine.

I should display a command window displaying:

I am logged on as XXX
My computer name is XXX
My IP addresses are XXXXXXXX, XXXXXXX

I have one that works, but it displays the ipconfig commands and adds
clutter.

ipconfig | FIND /I "ip address"

@echo I am logged in as %username%. My computer name is %computername%.


pause


How can this be cleaned up so they see "My IP address is (ip address)"
instead of ipconfig | FIND /I "ip address"

I can't resist Spamcop's galant invitation? Here you go:
@echo off
echo\
echo I am logged on as %UserName%.
echo My computer's name is %ComputerName%.
echo My IP settings are
ipconfig | find "." | find /i /v "suffix"
echo\
echo Press the Space bar to close this window.
pause > nul

If you want something a little more upmarket then this VB Script file should
fit the bill. You must unwrap any lines that your newsreader has wrapped
around, then remove the line numbers and save it as c:\xyz.vbs. You then
invoke it with this command:
wscript c:\xyz.vbs

[01] Set oWshShell = CreateObject("WScript.Shell")
[02] Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
[03] Set colNetAdapters = oWMIService.ExecQuery _
[04] ("Select * from Win32_NetworkAdapterConfiguration Where
IPEnabled=True")
[05] MacAddress = ""
[06] LF = Chr(10)
[07]
[08] For Each oNetAdapter In colNetAdapters
[09] If MacAddress = oNetAdapter.MACAddress then Exit For
[10] MacAddress = oNetAdapter.MACAddress
[11] sLine = oWshShell.ExpandEnvironmentStrings("User Name: %UserName%") &
LF _
[12] & oWshShell.ExpandEnvironmentStrings("Computer Name: %ComputerName%")
& LF _
[13] & "MAC Address: " & oNetAdapter.MACAddress & LF _
[14] & "DHCP Enabled: " & oNetAdapter.DHCPEnabled & LF _
[15] & Compile("IP Address",oNetAdapter.IPAddress) & LF _
[16] & Compile("Default Gateway", oNetAdapter.DefaultIPGateway) & LF _
[17] & Compile("Subnet Mask", oNetAdapter.IPSubnet) & LF _
[18] ' & Compile("DNS_Server", oNetAdapter.DNSServerSearchOrder) & LF
[19] Next
[20] MsgBox sLine, 0, "Status Report"
[21]
[22] Function Compile(Subject, Details)
[23] If IsArray(Details) Then
[24] For i = 0 To UBound(Details)
[25] Line = Subject & ": " & Details(i)
[26] Next
[27] Else
[28] Line = Subject & ": " & Details
[29] End If
[30] Compile = Line
[31] End Function
 
M

Mygposts

It doesn't have to be a batch file except it is slightly easier for the user
so they don't have to type .vbs extension. "Did you say dot vgs?"

We want the users to be able to just go to the Windows Run line and type
H:helpme (.bat files work without needing to type the extension) and have a
window pop up that has the info we need. They are not tech savvy and it
wastes time walking them through how to find their user name, host name and
IP address through the command line or GUI.

If a VBScript works mutch better, I will look at that if someone can post an
example.
 
S

SC Tom

Here, try this:

@ipconfig | FIND /I "ip address" >C:\ip.txt

@echo I am logged in as %username%.

@echo My computer name is %computername%.

@type C:\ip.txt

pause

Worked for me.

SC Tom
 
S

SC Tom

That should be @pause at the end. Also, if you tab once after each echo, all
the text will be left-justified.

SC Tom
 
T

Twayne

Mygposts said:
I need a batch file that a user can click on and have it display
their user name, machine name and ip addresses for that machine.

I should display a command window displaying:

I am logged on as XXX
My computer name is XXX
My IP addresses are XXXXXXXX, XXXXXXX

I have one that works, but it displays the ipconfig commands and adds
clutter.
@ echo off
ipconfig | FIND /I "ip address"

@echo I am logged in as %username%. My computer name is
%computername%.


pause


How can this be cleaned up so they see "My IP address is (ip address)"
instead of ipconfig | FIND /I "ip address"

Make the first line of the batch file "@ echo off" without the quotes,
of course. That hides all commands and shows only what you echo to the
STD IO.
There are all kinds of batch file tutorials around the 'net; check a
few of them out. Well worth the effort. A good newsgroup to see all
kinds of batch file talk and samples is
alt.msdos.batch.nt
It's specifically for XP Command Line batches, etc. Those guys can
really make .bat/.cmd files dance!

HTH,

Twayne`
 
S

SC Tom

Twayne said:
Make the first line of the batch file "@ echo off" without the quotes, of
course. That hides all commands and shows only what you echo to the STD
IO.
There are all kinds of batch file tutorials around the 'net; check a few
of them out. Well worth the effort. A good newsgroup to see all kinds of
batch file talk and samples is
alt.msdos.batch.nt
It's specifically for XP Command Line batches, etc. Those guys can really
make .bat/.cmd files dance!

HTH,

Twayne`

Just put a @ in front of IPCONFIG. I missed that on my earlier reply. DUH on
me!

SC Tom
 
B

Bernd

-------- Original-Nachricht --------
I need a batch file that a user can click on and have it display their user
name, machine name and ip addresses for that machine.

I should display a command window displaying:

I am logged on as XXX
My computer name is XXX
My IP addresses are XXXXXXXX, XXXXXXX

I have one that works, but it displays the ipconfig commands and adds clutter.

ipconfig | FIND /I "ip address"

@echo I am logged in as %username%. My computer name is %computername%.


pause


How can this be cleaned up so they see "My IP address is (ip address)"
instead of ipconfig | FIND /I "ip address"

An alternative would the BGINFO Tool from Sysinternals (now MS):

http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx

Bernd
 
G

Guest

SC Tom,

That example is already on the net because I saw it there myself yesterday.
Why not just link to it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top