中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-02 01:26
48,037 主题排行 / 350,122 发帖 / 今日 2 篇 / 48,250 会员排行
DOS批处理 & 脚本技术(批处理室) » 自己编的一个简单批处理文件 看看到底哪里出错了
可打印版本  1,261 / 6
第1楼 vk 发表于 2006-08-10 13:07
中级用户 发帖 86 积分 218
自己编的一个简单批处理文件 看看到底哪里出错了
@echo off
net share c$ /del
net share d$ /del
net share e$ /del
net share ADMIN$ /del
net share windows$ /del
if not errorlevel 0 goto no
if not errorlevel 1 goto ok
:no
echo 操作失败!>>no.txt
no.txt
del no.txt

:ok
echo 操作成功!>>ok.txt
ok.txt
del ok.txt


运行后如果不成功它会先跳到:no 这然后跳到:ok
怎么才能让它 如果不成功就跳到:no
为什么操作不成功它会跳到:ok这里?
请高人指点!
第2楼 bagpipe 发表于 2006-08-10 13:25
银牌会员 发帖 425 积分 1,144 来自 北京
呵呵,你这个当然在OK的时候就执行OK标签里的语句了,如果不成功,NO和OK标签里的内容都要执行,批处理是按照逐步执行的顺序来完成的,试试下面的

@echo off
net share c$ /del
net share d$ /del
net share e$ /del
net share ADMIN$ /del
net share windows$ /del
if not errorlevel 0 goto no
if not errorlevel 1 goto ok
:no
echo 操作失败!>>no.txt
no.txt
del no.txt
goto end
:ok
echo 操作成功!>>ok.txt
ok.txt
del ok.txt
:end

OR



@echo off
net share c$ /del
net share d$ /del
net share e$ /del
net share ADMIN$ /del
net share windows$ /del
if not errorlevel 0 goto no
if not errorlevel 1 goto ok
:no
echo 操作失败!>>no.txt
no.txt
del no.txt
goto :eof

:ok
echo 操作成功!>>ok.txt
ok.txt
del ok.txt
第3楼 namejm 发表于 2006-08-10 14:27
荣誉版主 发帖 1,737 积分 5,226 来自 成都
  如果要删除默认共享,这里有一篇类似的帖子,里面有更完善的解决方案。
批处理删除所有分区的默认共享:http://www.cn-dos.net/forum/viewthread.php?tid=21133&fpage=1&highlight=%E5%85%B1%E4%BA%AB
第4楼 vk 发表于 2006-08-10 18:37
中级用户 发帖 86 积分 218
懂了 谢谢
第5楼 iaide007 发表于 2006-09-10 17:26
初级用户 发帖 12 积分 36
呵。直接加exit 也行

@echo off
net share c$ /del
net share d$ /del
net share e$ /del
net share ADMIN$ /del
net share windows$ /del
if not errorlevel 0 goto no
if not errorlevel 1 goto ok
:no
echo 操作失败!>>no.txt
no.txt
del no.txt
exit

:ok
echo 操作成功!>>ok.txt
ok.txt
del ok.txt
exit
第6楼 bigeyes 发表于 2006-09-12 10:28
新手上路 发帖 8 积分 18
一个问题是 errorlevel 返回值判断不都是从大到小么?
现在版本都可以了么?
第7楼 IceCrack 发表于 2006-09-12 11:33
中级用户 发帖 168 积分 332 来自 天涯
好好看看三楼的链接吧!对你应该有帮助的
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023