|
ncow
初级用户
 
积分 38
发帖 13
注册 2005-11-18
状态 离线
|
『楼 主』:
请教如何写BAT获取计算机名或IP地址
使用 LLM 解释/回答一下
我想运行一个BAT,能生成一个以运行此BAT的计算机的名字或IP地址命名的文本文件.请教如何实现.
此BAT共享在服务器上.
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.
|
|
2006-3-16 15:37 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
ipconfig命令可以用来获得本机的IP地址。
net config workstation命令可以用来获得本机的计算机名。
剩下的工作就是将其中的相关数据提取到环境变量中用来生成相应的文件名,如何提取,方法多种多样,我想本论坛以前的帖子中已经提供了很多实例,自己努力一下找一找吧。
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.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-3-17 09:08 |
|
|
ncow
初级用户
 
积分 38
发帖 13
注册 2005-11-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
就请上面老大帮帮忙吧,给个完整的例子
我实在是找不到啊,搜索什么关键字好啊,"环境变量"……找不到啊
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.
|
|
2006-3-17 14:02 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
echo %COMPUTERNAME%
你什么系统?
echo %COMPUTERNAME%
What system are you using?
|
|
2006-3-17 14:13 |
|
|
ncow
初级用户
 
积分 38
发帖 13
注册 2005-11-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
4楼朋友你好,谢谢你。
我还要把此计算机名来命名新建的文本文件啊,请问如何,系统98和XP都有的。
echo 正在使用中.... >> %computername% +"正在使用中.....txt"
我想得到一个[计算机名+“正在使用中.....”]这个名字的文本文件。
请教
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 .
Please advise
|
|
2006-3-17 14:43 |
|
|
ncow
初级用户
 
积分 38
发帖 13
注册 2005-11-18
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
原来这么写就可以得到我想要的。
set a=%computername%正在使用中.....txt
echo >> %a%
但在98系统里得不到%computername%,请问98的计算机名如何获取。
再:
if 系统是98
set a=98的计算机名正在使用中.....txt
if 系统是XP
set a=%computername%正在使用中.....txt
以上应该怎么写啊
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?
|
|
2006-3-17 15:30 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
if /i %ComSpec% == C:\WINDOWS\system32\cmd.exe 就是98以上系统
if /i %ComSpec% == C:\WINDOWS\command.exe(具体路径是在system32下还是在windows目录下我忘记了,你自己看看吧) 就是98系统
其实只要一句就可以了
具体写发略。
另:如果你只是建立一个文件名而里面不需要别的内容的话可以省略到后缀,如:
echo > %computername%正在使用中
判断操作系统的方法其实很多,你也可以通过别的方法来判断,比如
if /i %os% == Windows_NT
你可以把你写的帖上来,然后大家帮你优化优化。。
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.
|
|
2006-3-17 16:03 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
楼上这位回答的已经很全面了。
The answer from the user above is already very comprehensive.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-3-17 16:08 |
|