Board logo

标题: [系统相关] 怎样根据卷标判断盘符?[同样的问题,求VBS方法] [打印本页]

作者: lon91ong    时间: 2008-9-27 17:42     标题: 怎样根据卷标判断盘符?[同样的问题,求VBS方法]

具体情况是这样,我用一个虚拟光驱加载一个镜像,所以这个盘符是不确定的,唯一能确定的只有光盘的卷标
我想再本地硬盘做一个批处理来调用光盘中的程序,这时候就需要通过卷标来判断虚拟光驱的盘符了

搜索了一下,没有找到这方面的知识

麻烦大侠帮忙解决一下!
多谢了!

[ 本帖最后由 lon91ong 于 2008-9-27 19:20 编辑 ]
作者: zqz0012005    时间: 2008-9-27 18:03

标题本来是很不错的,非要来三个“?”,画蛇添足。请楼主自觉规范一下,修改标题
  1. @echo off
  2. for /f "skip=1" %%a in ('wmic logicaldisk where "volumename='光盘卷标'" get name') do set "CDdrive=%%a"
  3. echo %CDdrive%
复制代码

[ 本帖最后由 zqz0012005 于 2008-9-27 18:05 编辑 ]
作者: lon91ong    时间: 2008-9-27 18:30

版主我真是爱死你了
一下午帮我解决了这么多问题!

试了一下楼上的代码,感觉速度好慢,而且用到了wmic

仅仅用命令行不能实现吗?或者用VBS也可以!


还有,版主的头像是谁呀?

[ 本帖最后由 lon91ong 于 2008-9-27 19:12 编辑 ]
作者: Batcher    时间: 2008-9-27 19:43

  1. @echo off
  2. for %%a 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 (
  3.   fsutil fsinfo drivetype %%a:|findstr /i "CD">nul&&echo 光驱盘符:%%a
  4. )
复制代码

作者: terse    时间: 2008-9-27 20:28

  1. @echo off
  2. 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 (
  3.   vol %%i:|findstr /i "cd">nul&&echo 光驱盘符:%%i&&goto ok
  4. )
  5. :ok
  6. pause
复制代码

作者: Batcher    时间: 2008-9-27 20:33     标题: 回复 5楼 的帖子

测试结果:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Test>type test.bat
@echo off
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 (
  vol %%i:|findstr /i "cd">nul&&echo 光驱盘符:%%i&&goto ok
)
k

C:\Test>test.bat
The device is not ready.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.

作者: terse    时间: 2008-9-27 21:05

原帖由 Batcher 于 2008-9-27 20:33 发表
测试结果:

我这里测试 上去的啊 用CD标测试

[ 本帖最后由 terse 于 2008-9-27 21:30 编辑 ]
作者: namejm    时间: 2008-9-27 22:13

  如果嫌wmic慢的话,就用vol命令吧,把if语句中的system改成你想要查询的卷标就可以了,演示如下:
  1. @echo off
  2. set drivers=c d e f g h i j k l m n o p q r s t u v w x y z
  3. for %%i in (%drivers%) do (
  4.     for /f "tokens=2,3*" %%j in ('vol %%i: 2^>nul') do if /i "%%l"=="system" echo %%j:
  5. )
  6. pause
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2