Discussion Locked

Win 98: Batch file to return PC name

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What I need is a way to return a computer name inside a batch file. I need to ID the computers that return a positive search result.

I am checking the workstations in the office for file sharing software. So I am scanning the PC in batch andif it finds the executables it returns a file to my pc. Naturally to successfully do this I need to get the PC name with this return file, any help on this would be greatly apprecited. Thank you!

5 replies

by joseph moore

%computername%
That is the variable for the machine name.
So, you could try something like this in your BAT file that if it finds a file called "filename.txt" on C: drive, it will write a message to a text file located on \\SERVER1 in the SHARE folder:

if exist c:\filename.txt goto POSITIVE
EXIT

:POSITIVE
echo Machine %computername% has the file! >> \\SERVER1\SHARE\filenamelog.txt
EXIT

hope this helps

by Former member

That works in NT and 2000, but doesnt seem to work in a 9x PC (at least not based on our test runs).

by phil.hall

Assuming you know the IP Address of the computers, you can simply redirect the output of NETSTAT -A to a file via:

NETSTAT -A >> \\wherever\to\place\file.txt

[The above is to be on one line.]

You can make a batchfile that will do this for you. Like this:

@ECHO OFF
IF EXIST GOTO MAIN
GOTO EOF
:MAIN
IF (GOTO:)==(%1) %1%2
For %%C in (IMPUT COMPUTER IP ADDRESSES HERE, SEPARATED BY SPACES) do call %0 GOTO: _SUBR %%C
GOTO EOF:_SUBR
ping -a -n 1 -w 1000 %3 | find "Pinging" | find "[" >> c:\windows\desktop\undone.txt
nbtstat -a %3 | find "<03>" >> c:\windows\desktop\undone.txt
:EOF

[Beware of line wrapping in the above]

The "C:\Windows\Desktop\undone.txt" is where you want the file to be written to. YOu can have multiple "IF EXIST" lines as well.

by Former member

The company I work for is currently using DHCP. If this would return the computer name, but as above the %computername% doesnt work with 9x PC's (at least not with the tests runs we have done).

by Former member

This question was closed by the author

This discussion is closed to new replies.