Board logo

标题: 自己编的一个简单批处理文件 看看到底哪里出错了 [打印本页]

作者: vk     时间: 2006-8-10 13:07    标题: 自己编的一个简单批处理文件 看看到底哪里出错了

@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这里?
请高人指点!
作者: bagpipe     时间: 2006-8-10 13:25
呵呵,你这个当然在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
作者: namejm     时间: 2006-8-10 14:27
  如果要删除默认共享,这里有一篇类似的帖子,里面有更完善的解决方案。
[已结]批处理删除所有分区的默认共享:http://www.cn-dos.net/forum/view ... =%E5%85%B1%E4%BA%AB
作者: vk     时间: 2006-8-10 18:37
懂了 谢谢
作者: iaide007     时间: 2006-9-10 17:26
呵。直接加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
作者: bigeyes     时间: 2006-9-12 10:28
一个问题是 errorlevel 返回值判断不都是从大到小么?
现在版本都可以了么?
作者: IceCrack     时间: 2006-9-12 11:33
好好看看三楼的链接吧!对你应该有帮助的