China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 14:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask about how to write a BAT to obtain the computer name or IP address View 2,612 Replies 7
Original Poster Posted 2006-03-16 15:37 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
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.
Floor 2 Posted 2006-03-17 09:08 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2006-03-17 14:02 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
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.
Floor 4 Posted 2006-03-17 14:13 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
echo %COMPUTERNAME%
What system are you using?
Floor 5 Posted 2006-03-17 14:43 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
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
Floor 6 Posted 2006-03-17 15:30 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
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?
Floor 7 Posted 2006-03-17 16:03 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Floor 8 Posted 2006-03-17 16:08 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The answer from the user above is already very comprehensive.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Forum Jump: