objDisk.MediaType을 확인하십시오. Here에는 MediaTypes 목록이 있습니다. 언뜻보기에 MediaType 1 ... 10은 '정상적인'플로피를 나타냅니다. 내 (가상) 컴퓨터의 빠른 확인에서 USB 드라이브가 Null (Unknown의 경우 Zero가 아님)의 MediaType을 보여 주므로 조심해야합니다. 두 번째로 (주의 사항에 대해) : 대부분의 정의 된 미디어 유형은 플로피 (일부는 이국적인)를 식별합니다. BTW - USB 플로피 드라이브는 어떨까요?
Const cnRemovableDisk = 2
Const cnMTypeUnknown = 0
Const cnMTypeNoFloppy = 11
Const cnMTypeFixedHD = 12
Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Dim colDisks : Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
Dim Removable : Removable = ""
Dim Floppy : Floppy = ""
Dim USBDrive : USBDrive = ""
Dim objDisk
For Each objDisk in colDisks
If objDisk.DriveType = cnRemovableDisk Then
Removable = Removable & ";" & objDisk.DeviceID & "\"
Select Case True
Case IsNull(objDisk.MediaType)
WScript.Echo objDisk.DeviceID, "has MediaType null - assuming USB Drive."
USBDrive = USBDrive & ";" & objDisk.DeviceID & "\"
Case objDisk.MediaType = cnMTypeNoFloppy
WScript.Echo objDisk.DeviceID, "has MediaType 11 - assuming USB Drive."
USBDrive = USBDrive & ";" & objDisk.DeviceID & "\"
Case objDisk.MediaType = cnMTypeUnknown
WScript.Echo objDisk.DeviceID, "has MediaType 0 - assuming USB Drive."
USBDrive = USBDrive & ";" & objDisk.DeviceID & "\"
Case objDisk.MediaType = cnMTypeFixedHD
WScript.Echo objDisk.DeviceID, "has MediaType 12 - how can this happen?"
Case Else
WScript.Echo objDisk.DeviceID, "has MediaType", objDisk.MediaType, " - surely some kind of floppy."
Floppy = Floppy & ";" & objDisk.DeviceID & "\"
End Select
End If
Next
Removable = Mid(Removable, 2)
Floppy = Mid(Floppy , 2)
USBDrive = Mid(USBDrive , 2)
WScript.Echo "Removable:", Removable
WScript.Echo "Floppy: ", Floppy
WScript.Echo "USBDrive: ", USBDrive
내 출력은 다음과 같습니다 :
A: has MediaType 5 - surely some kind of floppy.
F: has MediaType null - assuming USB Drive.
Removable: A:\;F:\
Floppy: A:\
USBDrive: F:\
나는 '진짜'컴퓨터에서 테스트 할 수 없습니다, 당신은 다음과 같은 코드를 한 번 확인해야합니다 USBDrive의 MediaType이 이상한 사고 일 수 있습니다. "Select Case True"제어 구조를 사용하여 MediaType을 쉽게 평가할 수 있도록 노력했습니다. VBScript는 첫 번째 진실이 될 때까지 사례의 조건을 테스트하고 해당 진술을 실행 한 다음 End Select로 '중단'합니다. 특별한 경우를 추가하거나 순서를 바꾸는 것은 간단합니다. IsNull 검사를 처음 위치에 두십시오.
안녕하세요 Ekkehard.Horner, 잘 했어요 :) Huuuuuuuuuge Thanks. 잘 작동합니다. 당신은 위대하다 :) 나에게 당신의 우편물을 줄 수 있니? – Nofuzy