我试图找到所有的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%
}发布于 2013-08-18 11:11:49
操作系统读取的可移动驱动器上有一点,并决定它们是否可移动(第一个字节的第7位)。
最有可能的情况是,驱动器没有被设置为可移动的,所以它们不是一个解决方案,除非您重写该位。重写位通常是不可能的,因为它在控制器上,而不是闪存空间。
发布于 2013-08-19 13:56:09
这似乎是使用这个职位脚本在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
}https://stackoverflow.com/questions/18298320
复制相似问题