中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 17:20
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » Ask about how to write a BAT to obtain the computer name or IP address
Printable Version  2,725 / 7
Floor1 ncow Posted 2006-03-16 15:37
初级用户 Posts 13 Credits 38
I want to run a BAT that can generate a text file named after the name or IP address of the computer that runs this BAT. Please advise how to achieve this. This BAT is shared on a server.
Floor2 Climbing Posted 2006-03-17 09:08
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
The ipconfig command can be used to obtain the IP address of the local machine.
The net config workstation command can be used to obtain the computer name of the local machine.
The remaining task is to extract the relevant data into environment variables to generate corresponding file names. There are various methods for extraction. I think many examples have been provided in the previous posts of this forum. Try to find them by yourself.
Floor3 ncow Posted 2006-03-17 14:02
初级用户 Posts 13 Credits 38
Just ask the senior above for help and give a complete example. I really can't find it. What key words should I search for? "Environment variables"... can't find it.
Floor4 3742668 Posted 2006-03-17 14:13
荣誉版主 Posts 718 Credits 2,013
echo %COMPUTERNAME%
What system are you using?
Floor5 ncow Posted 2006-03-17 14:43
初级用户 Posts 13 Credits 38
Friend on the 4th floor, hello, thank you.
I also need to name the newly created text file with this computer name. How to do it? Both Windows 98 and XP have this.

echo 正在使用中.... >> %computername% +"正在使用中.....txt"

I want to get a text file named [computer name + "正在使用中....."].
Please advise
Floor6 ncow Posted 2006-03-17 15:30
初级用户 Posts 13 Credits 38
So this way can get what I want.
set a=%computername% is in use.....txt
echo >> %a%

But in the 98 system, %computername% cannot be obtained. How to get the computer name of 98?
Again:
if the system is 98
set a=Computer name of 98 is in use.....txt
if the system is XP
set a=%computername% is in use.....txt
How should the above be written?
Floor7 3742668 Posted 2006-03-17 16:03
荣誉版主 Posts 718 Credits 2,013
if /i %ComSpec% == C:\WINDOWS\system32\cmd.exe is for systems above 98
if /i %ComSpec% == C:\WINDOWS\command.exe (I forgot whether the specific path is under system32 or in the windows directory, you can check it yourself) is for Windows 98 system
Actually, just one sentence is enough
The specific writing is omitted.
Another: If you just create a file name and don't need other content inside, you can omit the suffix, such as:
echo > %computername% is in use
There are actually many ways to judge the operating system. You can also judge by other methods, such as
if /i %os% == Windows_NT
You can post what you wrote, and everyone can help you optimize it.
Floor8 Climbing Posted 2006-03-17 16:08
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
The answer from the user above is already very comprehensive.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023