首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Autohotkey中找到USB连接的可移动硬盘驱动器?

如何在Autohotkey中找到USB连接的可移动硬盘驱动器?
EN

Stack Overflow用户
提问于 2013-08-18 10:53:56
回答 2查看 1.2K关注 0票数 1

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

命令DriveGet,类型应返回这些值“未知、可移动、固定、网络、CDROM、RAMDisk.”。

下面的脚本为每个驱动器返回“固定”,不管它是如何连接的。

有办法解决这个问题吗?

代码语言:javascript
复制
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%

}
EN

回答 2

Stack Overflow用户

发布于 2013-08-18 11:11:49

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

最有可能的情况是,驱动器没有被设置为可移动的,所以它们不是一个解决方案,除非您重写该位。重写位通常是不可能的,因为它在控制器上,而不是闪存空间。

票数 1
EN

Stack Overflow用户

发布于 2013-08-19 13:56:09

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

代码语言:javascript
复制
#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 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18298320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档