General discussion

Locked

Win 98: Batch file to return PC name

By Mike Drynan ·
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!

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Win 98: Batch file to return PC name

by Joseph Moore In reply to Win 98: Batch file to ret ...

%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

Collapse -

Win 98: Batch file to return PC name

by Mike Drynan In reply to Win 98: Batch file to ret ...

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

Collapse -

Win 98: Batch file to return PC name

by phil.hall In reply to Win 98: Batch file to ret ...

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

NETSTAT -A <ip_address> >> \\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 <THE FILE YOU'RE LOOKING FOR> 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.

Collapse -

Win 98: Batch file to return PC name

by Mike Drynan In reply to Win 98: Batch file to ret ...

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).

Collapse -

Win 98: Batch file to return PC name

by Mike Drynan In reply to Win 98: Batch file to ret ...

This question was closed by the author

Back to Windows Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums