|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『楼 主』:
[寻求完善]一个判断光驱的新办法
使用 LLM 解释/回答一下
问题是这样引起的。
看见别人写了个判断 光盘的例子
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\WIN51 set CDROM=%%i
上边的方法很简单, 但有个问题,就是当光驱中没有光盘的时候,会弹出错误信息,然后后边的命令就无法执行, 更糟糕的是, 如果有双光驱, 光盘在第2个光驱的时候, 根本就无法得到结果, 因为第一个光驱读不出, 第2个光驱无法检测。
于是我利用 Dready 这个小程序, 这个小程序用法是 Dready /w, 返回 errorlevel 0,1,2,255, 如果返回1, 表示是 Readonly, 也就是表示这个是光驱, 并且准备好了。
我改了下程序
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do Dready %%i &if errorlevel 1 echo %%i>>cdrom.txt
我的设想是先检测出可读的光驱到临时文件中,然后再次用 For 命令检测光驱中文件 WIN51, 第2步 很容易编, 问题就出在上边的第一步。
cdrom.txt 文件的结果不是我希望的, 因为errorlevel 的值一直是检测最后一个光驱的值, 我想这就是延迟变量的问题。
于是我在程序中 加入 setlocal ENABLEDELAYEDEXPANSION
并使用 !errorlevel! 代替 %errorlevel %, 但实际发现 !errorlevel!不是一个数值, 而是 !errorlevel!本身
最后我简单编了个 程序如下:
setlocal ENABLEDELAYEDEXPANSION
set test="No problem"
echo !test!
实际运行结果不是 No probelm, 而是 !test!, 这是怎么回事??
我照抄例子的时候是对的, 我自己编却错,而且也不是 !全角半角的问题,这点知识我还是有的。
我为了避免错误, 很多句子是拷贝的, 只是 set=xxx 的自己写, 可是就是错误, 我想不通了。
请大家帮帮我, 谢谢!
Last edited by quya on 2008-5-29 at 12:41 PM ]
The problem arises like this.
I saw someone wrote an example of judging the CD - ROM:
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\WIN51 set CDROM=%%i
The above method is very simple, but there is a problem. That is, when there is no CD - ROM in the optical drive, an error message will pop up, and then the subsequent commands cannot be executed. What's worse, if there are two optical drives and the CD - ROM is in the second optical drive, the result cannot be obtained at all because the first optical drive cannot be read and the second optical drive cannot be detected.
So I used the Dready small program. The usage of this small program is Dready /w, which returns errorlevel 0, 1, 2, 255. If it returns 1, it means it is Readonly, that is, it means this is an optical drive and it is ready.
I modified the program:
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do Dready %%i &if errorlevel 1 echo %%i>>cdrom.txt
My idea is to first detect the readable optical drives into a temporary file, and then use the For command again to detect the file WIN51 in the optical drive. The second step is easy to compile. The problem is in the first step above.
The result of the cdrom.txt file is not what I expected because the value of errorlevel has always been the value of the last detected optical drive. I think this is the problem of delayed variables.
So I added setlocal ENABLEDELAYEDEXPANSION in the program and used!errorlevel! instead of %errorlevel%, but I actually found that!errorlevel! is not a value but!errorlevel! itself.
Finally, I simply compiled a program as follows:
setlocal ENABLEDELAYEDEXPANSION
set test="No problem"
echo !test!
The actual running result is not No problem, but!test!, what's the matter?
When I copied the example, it was correct. When I compiled it myself, it was wrong, and it's not the problem of full - width and half - width. I still have this knowledge.
In order to avoid mistakes, many sentences are copied. I just wrote set = xxx myself, but it's wrong. I can't figure it out.
Please help me, thank you!
Last edited by quya on 2008 - 5 - 29 at 12:41 PM ]
|

我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已. |
|
2008-5-26 19:04 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
把你的完整代码贴出来看看
Please provide the Chinese text content that needs to be translated so that I can perform the translation as required.
|

 |
|
2008-5-26 19:10 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
看看这个适合你不。
@echo off
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
for /f "delims=" %%i in ('%var2% %%a: ^| find/i "cd-rom"') do call :loop "%%i"
)
pause&exit
:loop
set num=%~1
set num=%num:~0,1%
if exist %num%:\nul.ext (
echo.&echo 光盘是 %num% 盘 里面有光盘
) else (
echo.&echo 光盘是 %num% 盘 无光盘
)
goto :eof
Last edited by 26933062 on 2008-5-26 at 07:33 PM ]
See if this suits you.
@echo off
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
for /f "delims=" %%i in ('%var2% %%a: ^| find/i "cd-rom"') do call :loop "%%i"
)
pause&exit
:loop
set num=%~1
set num=%num:~0,1%
if exist %num%:\nul.ext (
echo.&echo The CD-ROM is drive %num%, there is a CD inside
) else (
echo.&echo The CD-ROM is drive %num%, no CD
)
goto :eof
Last edited by 26933062 on 2008-5-26 at 07:33 PM ]
|

致精致简! |
|
2008-5-26 19:19 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
3楼的, 你的代码好神奇, 我看不懂, 但功能确实是我需要的。
你代码很复杂, 我想学也无从学起。
估计要你解释,即使你有耐心我也不一定懂。
我只想奢望地问你一下,如果按我思路编, 应该怎么编? 因为我知道我的代码。
谢谢你!!!!
Post #3, your code is really amazing. I don't understand it, but the functionality is exactly what I need.
Your code is quite complex, and I have no way to start learning it.
It's estimated that even if you are patient, I may not understand it if you explain it.
I just want to humbly ask you, how should I code according to my train of thought? Because I know my code.
Thank you!!!
|
|
2008-5-26 20:07 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
哈哈, 有点理解你的代码了, 因为 fsutil 居然是个命令。
而且 fsutil fsinfo drivetype [drives] 会显示 “CD-ROM”,“固定驱动器” 之类的东西。
太感谢了, 学了一招!
Haha, I kind of understand your code because fsutil is actually a command.
And fsutil fsinfo drivetype will display things like "CD-ROM", "fixed drive" and so on.
Thank you so much, I learned a trick!
|
|
2008-5-26 20:17 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
好像还是不行,我在第一个光驱中放盘, 第2个光驱无盘。成功显示信息
第2次倒过来,第2个光驱放,第一个光驱不放,就出现弹出信息。
之后又恢复到第1种情况, 还是弹出。
重复N次, 再没成功过。
不解中.......
It still doesn't work. I put a disc in the first CD drive and the second CD drive has no disc. The information is successfully displayed.
The second time it's reversed, the second CD drive has the disc and the first CD drive has no disc, then a pop-up message appears.
Then it returns to the first situation again, still popping up.
Repeated N times, and it hasn't succeeded anymore.
Puzzled.......
|
|
2008-5-26 20:37 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 7 楼』:
楼主试试这个:
使用 LLM 解释/回答一下
@echo off
for /f "delims=驱动器:\ " %%i in ('fsutil fsinfo drives^|more') do fsutil fsinfo drivetype %%i: |findstr "CD-ROM">nul&&call :lp %%i
pause>nul&goto :eof
:lp
if exist %1:\autorun.inf (
echo 光驱%1:中有盘。
) else(
echo 光驱%1:中无盘。
)
Last edited by zw19750516 on 2008-5-26 at 10:14 PM ]
```
@echo off
for /f "delims=驱动器:\ " %%i in ('fsutil fsinfo drives^|more') do fsutil fsinfo drivetype %%i: |findstr "CD-ROM">nul&&call :lp %%i
pause>nul&goto :eof
:lp
if exist %1:\autorun.inf (
echo There is a disc in drive %1.
) else(
echo There is no disc in drive %1.
)
```
Last edited by zw19750516 on 2008-5-26 at 10:14 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-5-26 21:22 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
:这样呢
@echo off
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
for /f "delims=" %%i in ('%var2% %%a: ^| find/i "cd-rom"') do call :loop "%%i"
)
echo.&pause&exit
:loop
set num=%~1&set "str="
set "num=%num:~0,1%"
dir %num%: >nul 2>nul
if %ERRORLEVEL% equ 0 (echo.&echo 光盘是 %num% 盘 里面有光盘) else (
echo.&echo 光盘是 %num% 盘 无光盘
)
goto :eof
Last edited by 26933062 on 2008-5-26 at 10:16 PM ]
:How about this
@echo off
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
for /f "delims=" %%i in ('%var2% %%a: ^| find/i "cd-rom"') do call :loop "%%i"
)
echo.&pause&exit
:loop
set num=%~1&set "str="
set "num=%num:~0,1%"
dir %num%: >nul 2>nul
if %ERRORLEVEL% equ 0 (echo.&echo The CD is drive %num%, there is a CD inside) else (
echo.&echo The CD is drive %num%, no CD
)
goto :eof
Last edited by 26933062 on 2008-5-26 at 10:16 PM ]
|

致精致简! |
|
2008-5-26 22:12 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
7 楼的程序有错误
8楼的快接近完美了, 可是有点小错。运行结果如下:
光盘是 H 盘 无光盘
光盘是 I 盘 里面有光盘
请按任意键继续. . .
光盘是 ~0,1 盘 无光盘
能把最后一个无效信息去掉就更好,我也正在研究,何处会发生这个小错。
再次感谢!
8楼构思巧妙, 用dir 无光盘光驱只会显示“设备未就绪”(不会弹错误信息), 比那个判断 if exist 文件的句子要强太多!!! 晕! 为什么大家只想到了后者?
Last edited by quya on 2008-5-26 at 10:32 PM ]
There is an error in the program on floor 7. The one on floor 8 is almost perfect, but there is a small mistake. The running results are as follows:
The CD - ROM is drive H, no CD - ROM.
The CD - ROM is drive I, there is a CD - ROM inside.
Press any key to continue...
The CD - ROM is drive ~0,1, no CD - ROM.
It would be better to remove that last invalid message. I am also researching where this small mistake occurs.
Thanks again!
The idea of floor 8 is ingenious. Using dir on a CD - ROM without a CD - ROM will only display "Device not ready" (no error message will be popped up), which is much better than that judgment sentence of if exist file!!! Oh! Why do everyone only think of the latter?
Last edited by quya on 2008 - 5 - 26 at 10:32 PM ]
|
|
2008-5-26 22:27 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
这个错误信息是在 请按任意键继续. . . 之后出现的吗?
如果是,你确定你是完全复制8楼的代码的吗?那后面是有exit的啊!!~~~
Is this error message appearing after "Press any key to continue..."? If yes, are you sure you copied the code from building 8 completely? Because there is exit later!!~~~
|

致精致简! |
|
2008-5-26 22:33 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
整理了一下
@echo off&setlocal EnableDelayedExpansion
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
%var2% %%a: | find/i "cd-rom">nul&&(
set "str=%%a"
set "str=!str:~0,1!"
dir !str!: >nul 2>nul
if !ERRORLEVEL! equ 0 (echo.&echo 光盘是 !str! 盘 里面有光盘) else (
echo.&echo 光盘是 !str! 盘 无光盘
)))
echo.&pause&exit
I've sorted it out
@echo off&setlocal EnableDelayedExpansion
set "var1=fsutil fsinfo drives"
set "var2=fsutil fsinfo drivetype"
for /f "skip=2 tokens=1 delims=:" %%a in ('%var1%^|more') do (
%var2% %%a: | find/i "cd-rom">nul&&(
set "str=%%a"
set "str=!str:~0,1!"
dir !str!: >nul 2>nul
if !ERRORLEVEL! equ 0 (echo.&echo The CD-ROM is drive !str! and there is a CD in it) else (
echo.&echo The CD-ROM is drive !str! and there is no CD
)))
echo.&pause&exit
|

致精致简! |
|
2008-5-26 22:43 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
我因为要调试, 而且以后要用在批处理,并且还要赋值,所以不能 EXIT
dir >nul 2>nul 那个 2>nul 什么意思? 不写这个, 有信息回显。 我还试了 3>nul , 结果似乎进入一个shell了,只好 EXIT 退出,昏! 从来没看到这样的用法, “26933062” 是强人, 不佩服不行。
I need to debug, and it will be used in batch processing later, and also need to assign values, so I can't EXIT. What does "2>nul" mean in "dir >nul 2>nul"? Without writing this, there is information echoing. I also tried "3>nul", and it seemed to enter a shell, so I had to EXIT and quit. Oh! I've never seen such a usage before. "26933062" is an expert, I have to admire.
|
|
2008-5-26 22:57 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
不能用exit就改为 goto 目标标签,
否则,再显示完后继续运行:loop下面的代码当然就会出现你9楼说的错误情况了。
或者用11楼的就可以了。
Instead of using exit, change it to goto target label. Otherwise, after displaying, it will continue to run: the code below loop will naturally cause the error you mentioned in building 9. Or using the one in building 11 will work.
|

致精致简! |
|
2008-5-26 22:59 |
|
|
quya
高级用户
    五星老土
积分 558
发帖 172
注册 2003-2-9 来自 江苏
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
谢谢 26933062, 我之所以要这样一个批处理, 因为我想制作一个 多合一 的XP SP3 安装盘。
目前大多数的多合一盘是有菜单的, 我想做一个无菜单的, 可自动监测机器是否是 OEM机器,如果是,则安装OEM相应版本 (如果光盘上有相应文件), 否则装 VOL版的。
无菜单的好处是可以提高光盘启动的兼容性。
我差不多已经完成了, 其实现在要的程序在实际安装系统的中途是不会把光盘取出来的(但依旧存在双光驱的问题), 但我想可能有人会把我的部分程序拷到硬盘执行,那么就会出现错误信息,我觉得非常不爽, 这才苦思冥想要解决。
今天真是学到东西了!
在实现这个设想的过程中,我用到了一些dos命令,都是用的很笨的命令,但实现的功能在我看起来很复杂。 26933062, 你很强, 我的乱七八糟代码如果你看到恐怕会笑死。
Last edited by quya on 2008-5-26 at 11:16 PM ]
Thanks to 26933062. The reason I need such a batch is that I want to make a multi-in-one XP SP3 installation disc.
Most current multi-in-one discs have menus. I want to make one without a menu, which can automatically detect whether the machine is an OEM machine. If it is, install the corresponding OEM version (if the corresponding file is on the disc); otherwise, install the VOL version.
The advantage of no menu is that it can improve the boot compatibility of the disc.
I'm almost done. Actually, the program I need now won't have the disc removed during the actual system installation (but there's still the problem of dual CD-ROM drives), but I think someone might copy my part of the program to the hard drive and execute it, which would cause error messages. I find it very annoying, so I've been racking my brains to solve it.
I really learned something today!
In the process of realizing this idea, I used some DOS commands, all very crude commands, but the functions realized seem very complicated to me. 26933062, you're awesome. If you saw my messy code, you'd probably laugh.
Last edited by quya on 2008-5-26 at 11:16 PM ]
|
|
2008-5-26 23:13 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 15 楼』:
回复 14 楼
使用 LLM 解释/回答一下
别客气,大家相互帮助的同时,其实自己也在进步。
你夸我夸的过了,这个论坛里,高手如云,我岂敢妄谈“强”字。
好好看看这里的老帖,你会知道什么才是真正的 强 !
You're welcome. When everyone helps each other, in fact, one is also improving oneself.
You've praised me too much. In this forum, there are many experts, how dare I talk about the word "strong" casually.
Take a good look at the old posts here, and you'll know what real strength is!
|

致精致简! |
|
2008-5-26 23:33 |
|