中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-08 22:16
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » [Seeking Improvement] A New Method to Judge the CD-ROM Drive
Printable Version  2,805 / 17
Floor1 quya Posted 2008-05-26 19:04
高级用户 Posts 172 Credits 558 From 江苏
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 ]
Floor2 HAT Posted 2008-05-26 19:10
版主 Posts 5,017 Credits 9,023
Please provide the Chinese text content that needs to be translated so that I can perform the translation as required.
Floor3 26933062 Posted 2008-05-26 19:19
银牌会员 Posts 879 Credits 2,268
See if this suits you.


[ Last edited by 26933062 on 2008-5-26 at 07:33 PM ]
Floor4 quya Posted 2008-05-26 20:07
高级用户 Posts 172 Credits 558 From 江苏
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!!!
Floor5 quya Posted 2008-05-26 20:17
高级用户 Posts 172 Credits 558 From 江苏
Haha, I kind of understand your code because fsutil is actually a command.

And fsutil fsinfo drivetype [drives] will display things like "CD-ROM", "fixed drive" and so on.

Thank you so much, I learned a trick!
Floor6 quya Posted 2008-05-26 20:37
高级用户 Posts 172 Credits 558 From 江苏
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.......
Floor7 bat-zw Posted 2008-05-26 21:22
金牌会员 Posts 1,276 Credits 3,105
```
@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 ]
Floor8 26933062 Posted 2008-05-26 22:12
银牌会员 Posts 879 Credits 2,268
:How about this


[ Last edited by 26933062 on 2008-5-26 at 10:16 PM ]
Floor9 quya Posted 2008-05-26 22:27
高级用户 Posts 172 Credits 558 From 江苏
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 ]
Floor10 26933062 Posted 2008-05-26 22:33
银牌会员 Posts 879 Credits 2,268
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!!~~~
Floor11 26933062 Posted 2008-05-26 22:43
银牌会员 Posts 879 Credits 2,268
I've sorted it out
Floor12 quya Posted 2008-05-26 22:57
高级用户 Posts 172 Credits 558 From 江苏
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.
Floor13 26933062 Posted 2008-05-26 22:59
银牌会员 Posts 879 Credits 2,268
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.
Floor14 quya Posted 2008-05-26 23:13
高级用户 Posts 172 Credits 558 From 江苏
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 ]
Floor15 26933062 Posted 2008-05-26 23:33
银牌会员 Posts 879 Credits 2,268
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!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023