Board logo

标题: 求教:vbs中获取当前盘类型 [打印本页]

作者: lummox     时间: 2009-9-1 15:13    标题: 求教:vbs中获取当前盘类型

如题。

在类似的程序中,是通过遍历所有驱动器来获得磁盘类型的:

For Each disk In disks
……
Next

我的问题是:
如何直接取得磁盘类型?
        如果当前盘类型<>1          (if ... then 语句) [这是我求教的]
     显示  "当前盘X:\ 盘不是可移动盘,请在移动盘下执行本程序"
        退出程序
        结束判断                 (End If)
作者: qinchun36     时间: 2009-9-1 23:09

Function ShowDriveType(objdrive)
   Dim fso, d, t, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set d = fso.GetDrive(objdrive)
   Select Case d.DriveType
      Case 0: t = "Unknown"
      Case 1: t = "Removable"
      Case 2: t = "Fixed"
      Case 3: t = "Network"
      Case 4: t = "CD-ROM"
      Case 5: t = "RAM Disk"
   End Select
   s = "Drive: " & d.DriveLetter & "(" & d.VolumeName & ");  Type: " & t
   Wscript.Echo s
End Function

Set fso = CreateObject("Scripting.FileSystemObject")
Set objdrives=fso.Drives
For Each objdrive In objdrives
ShowDriveType(objdrive)
Next
对于你的问题:
Dim drvName, drv
Set fso = CreateObject("Scripting.FileSystemObject")
drvName = left(Wscript.ScriptFullName, 1)
Set drv = fso.GetDrive(drvName)

If drv.DriveType <> 1 Then
msgbox "当前盘 " & Ucase(drvName) & ":\ 盘不是可移动盘,请在移动盘下执行本程序", 16, "警告"
Wscript.Quit
End If

msgbox "这下面是一些基于可移动磁盘 " & Ucase(drvName) & ":\ 的命令。", 64, "完成"
[ Last edited by qinchun36 on 2009-9-1 at 23:29 ]