1

我正在尝试查找连接到我的系统的所有 USB 硬盘驱动器/SSD。

命令 DriveGet, , Type 应该返回这些值“ Unknown, Removable, Fixed, Network, CDROM, RAMDisk。

下面的脚本为每个驱动器返回“ Fixed ”,无论它是如何连接的。

有没有办法来解决这个问题?

DriveGet, DriveList , List,
Loop,

{

  MyDrive :=  SubStr(Drivelist, A_Index,1)  

  If (MyDrive = "")
    break

  MyDrive = %MyDrive%

  DriveGet, MyLabel, serial, %MyDrive%
  DriveGet, MyType, Type,  %MyDrive%:\
  msgbox, Drive %MyDrive% Type %MyType%

}
4

2 回答 2

1

操作系统读取的可移动驱动器上有一些内容,并决定它们是否可移动(第一个字节的第 7 位)。

最可能的情况是驱动器未设置为可移动,因此除非您重写该位,否则它们不是解决方案。重写该位通常是不可能的,因为它在控制器上,而不是在闪存存储空间上。

于 2013-08-18T11:11:49.233 回答
1

似乎这是在 Autohotkey 论坛上使用此帖子中的脚本解决的问题。我已经包含了下面线程中的脚本。试试看。

#NoEnv
#SingleInstance force
SetBatchLines -1
ListLines Off
SendMode Input
SetWorkingDir %A_ScriptDir%


    pd := PhysicalFromLogical("F")       ; This is the drive you want to test
    if GetType(pd) = "Fixed" and GetInterface(pd) = "USB"
        MsgBox Drive is Fixed and USB
    else
        MsgBox Drive is either not Fixed or not USB
return


; Given a drive letter like "f" return the physical
; drive associated with it, i.e. \\\\.\\PHYSICALDRIVE2
PhysicalFromLogical(d)
{
    wmi := ComObjGet("winmgmts:")

    for LogicalDisk in wmi.ExecQuery("Select * from Win32_LogicalDiskToPartition")
        if InStr(LogicalDisk.Dependent,d)
            for Partition in wmi.ExecQuery("Select * from Win32_DiskDriveToDiskPartition")
                if (Partition.Dependent = LogicalDisk.Antecedent) {
                    Start := InStr(Partition.Antecedent, """") + 1
                    return SubStr(Partition.Antecedent, Start, -1)
                }
    return 0
}

; Given a drive path like \\\\.\\PHYSICALDRIVE2 return the
; drives interface type, i.e. "USB"
GetInterface(pd)
{
    wmi := ComObjGet("winmgmts:")

    for Drive in wmi.ExecQuery("Select * from Win32_DiskDrive where DeviceId = """ pd """")
        return Drive.InterfaceType
    return 0
}

; Given a drive path like \\\\.\\PHYSICALDRIVE2 return the drive type, i.e. "Removable"
; This is just a wrapper for DriveGet
GetType(pd)
{
    StringReplace pd, pd, \\, \, All
    DriveGet out, Type, %pd%
    return out 
}
于 2013-08-19T13:56:09.070 回答