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-02 06:00
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can I make a batch file execute according to the machine name?? View 952 Replies 4
Original Poster Posted 2006-10-19 02:14 ·  中国 贵州 黔东南苗族侗族自治州 凯里市 电信
新手上路
Credits 16
Posts 4
Joined 2006-04-22 11:28
20-year member
UID 54252
Status Offline
I wrote a batch file and want it to run according to the machine's name. For example, machines starting with "A" won't run it, and machines starting with "Y" will. How can this be done using only batch processing, without any tools????
Floor 2 Posted 2006-10-19 04:56 ·  中国 浙江 宁波 电信
初级用户
Credits 44
Posts 15
Joined 2006-10-18 12:14
19-year member
UID 66379
Status Offline
Would it be like this:
if %COMPUTERNAME:~0,1% == "A" goto :end
if %COMPUTERNAME:~0,1% == "Y" goto :执行体
others....
Floor 3 Posted 2006-10-19 07:07 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Mm, the code from the poster above can solve the OP's problem exactly.
Floor 4 Posted 2006-10-20 02:30 ·  中国 贵州 黔东南苗族侗族自治州 凯里市 电信
新手上路
Credits 16
Posts 4
Joined 2006-04-22 11:28
20-year member
UID 54252
Status Offline
Thanks, everyone.. I also found a method myself, sharing it.. hehe...
echo %userdomain% | find /i "y" && goto y
Floor 5 Posted 2006-10-20 03:42 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by gzrjhxh at 2006-10-20 02:30:
Thanks, everyone.. I also found a method myself, sharing it.. hehe...
echo %userdomain% | find /i "y" && goto y

Hehe, try it a few more times and you'll know this one's drawback
Forum Jump: