China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-23 01:36
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question: get the current drive type in VBS View 616 Replies 1
Original Poster Posted 2009-09-01 15:13 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
As the title says.

In similar programs, the disk type is obtained by traversing all drives:

For Each disk In disks
……
Next

My question is:
How can I directly get the disk type?
If current drive type<>1 (if ... then statement) [This is what I'm asking about]
display "The current drive X:\ is not a removable drive; please run this program from a removable drive"
exit the program
end the judgment (End If)
Floor 2 Posted 2009-09-01 23:09 ·  中国 天津 联通
高级用户
★★★
据说是李先生
Credits 609
Posts 400
Joined 2008-04-23 15:55
18-year member
UID 116706
Gender Male
Status Offline

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


As for your question:


Dim drvName, drv
Set fso = CreateObject("Scripting.FileSystemObject")
drvName = left(Wscript.ScriptFullName, 1)
Set drv = fso.GetDrive(drvName)

If drv.DriveType <> 1 Then
msgbox "The current drive " & Ucase(drvName) & ":\ is not a removable drive; please run this program from a removable drive", 16, "Warning"
Wscript.Quit
End If

msgbox "Below are some commands based on the removable disk " & Ucase(drvName) & ":\ .", 64, "Done"


[ Last edited by qinchun36 on 2009-9-1 at 23:29
Forum Jump: