我正在尝试找到连接到我系统的所有USB硬盘/ SSD。
命令 DriveGet ,,键入 应该返回这些值 “未知,可移动,固定,网络,CDROM,RAMDisk。”
以下脚本为每个驱动器返回“固定”,无论它是如何连接的。
有没有办法解决这个问题?
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%
}
答案 0 :(得分:1)
操作系统读取的可移动驱动器上有一点,并决定它们是否可移动(第一个字节的第7位)。
最可能的情况是驱动器未设置为可移动,因此除非您重写该位,否则它们不是解决方案。通常不可能重写位,因为它位于控制器上,而不是闪存存储空间。
答案 1 :(得分:1)
这似乎是使用this post中的脚本在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
}