1 Star 1 Fork 0

gfcocos/autohotkey

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Removable.ahk 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
;Removable.ahk
; Eject removable drives by doubleclicking.
;Skrommel @2007
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
applicationname=Driver List
Gui, Destroy
Gui, +Resize ;-Border -Caption
Gui,Margin,0,0
Gui,Add,ListView, AltSubmit Grid vlistview gLISTVIEW,Drive|Label|Type|Free Space|Capacity|Filesystem|Status|Serial Number
Gui,Add,Button,vrefresh_btn gRefreshDrivers, Refresh
Menu, MyContextMenu, Add, Open, OPENDRIVER
Menu, MyContextMenu, Add, Eject, EJECT
gosub RefreshDrivers
Loop,8
LV_ModifyCol(A_Index,"AutoHdr")
LV_ModifyCol(4,"Integer Right")
LV_ModifyCol(5,"Integer Right")
LV_ModifyCol(8,"Integer Right")
;LV_ModifyCol(3,"SortDesc")
Gui,Show,w600 h200,%applicationname%
Return
RefreshDrivers:
LV_Delete()
DriveGet,list,List
Loop,Parse,list,
{
drive:=A_LoopField ":"
Gosub,DRIVEGET
LV_Add("",drive,label,type,free " MB",capacity " MB",fs,status,serial)
}
return
DRIVEGET:
DriveGet,type,Type,%drive%\
If type=CDROM
DriveGet,status,StatusCD,%drive%\
Else
DriveGet,status,Status,%drive%\
DriveGet,capacity,Capacity,%drive%\
If capacity=
capacity=0
StringSplit,part_,capacity,
capacity=
Loop,% part_0
{
If ((A_Index=4 Or A_Index=8) And part_0>A_Index)
capacity:=capacity ","
pos:=part_0-A_Index+1
capacity:=capacity . part_%pos%
}
DriveSpaceFree,free,%drive%\
If free=
free=0
StringSplit,part_,capacity,
free=
Loop,% part_0
{
If ((A_Index=4 Or A_Index=8) And part_0>A_Index)
free:=free ""
pos:=part_0-A_Index+1
free:=free . part_%pos%
}
DriveGet,fs,Fs,%drive%\
DriveGet,label,Label,%drive%\
DriveGet,serial,Serial,%drive%\
Return
LISTVIEW:
row:=A_EventInfo
If A_GuiEvent=RightClick
Gosub,ContextMenu
If A_GuiEvent=DoubleClick
gosub, OPENDRIVER
Return
ContextMenu:
LV_GetText(status,row,7)
if (status != "ready")
return
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
OPENDRIVER:
LV_GetText(drive,row,1)
LV_GetText(status,row,7)
if (status != "ready")
return
run, %drive%
return
EJECT:
LV_GetText(drive,row,1)
LV_GetText(label,row,2)
LV_GetText(type,row,3)
LV_GetText(free,row,4)
LV_GetText(capacity,row,5)
LV_GetText(fs,row,6)
;LV_GetText(status,row,7)
LV_GetText(serial,row,8)
If type=CDROM
{
DriveGet,status,StatusCD,%drive%\
If status=open
{
ToolTip,Retracting %drive%...
Drive,Eject,%drive%,1
}
Else
{
ToolTip,Ejecting %drive%...
Drive,Eject,%drive%
}
}
If type=Removable
{
DriveGet,status,Status,%drive%\
If status=NotReady
ToolTip,%drive% already disconnected
Else
{
ToolTip,Disconnecting %drive%...
hVolume := DllCall("CreateFile"
, Str, "\\.\" . drive
, UInt, 0x80000000 | 0x40000000 ; GENERIC_READ | GENERIC_WRITE
, UInt, 0x1 | 0x2 ; FILE_SHARE_READ | FILE_SHARE_WRITE
, UInt, 0
, UInt, 0x3 ; OPEN_EXISTING
, UInt, 0, UInt, 0)
if hVolume <> -1
{
DllCall("DeviceIoControl"
, UInt, hVolume
, UInt, 0x2D4808 ; IOCTL_STORAGE_EJECT_MEDIA
, UInt, 0, UInt, 0, UInt, 0, UInt, 0
, UIntP, dwBytesReturned ; Unused.
, UInt, 0)
DllCall("CloseHandle", UInt, hVolume)
}
}
}
Sleep,3000
ToolTip
Gosub,DRIVEGET
LV_Modify(row,"",drive,label,type,free,capacity,fs,status,serial)
Return
GuiSize:
If A_EventInfo = 1 ; Minimized
Return
GuiControl,Move,listview,% "W" . (A_GuiWidth) . " H" . (A_GuiHeight-25)
GuiControl,Move,refresh_btn,% " Y" . (A_GuiHeight-25)
Return
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
AutoHotkey
1
https://gitee.com/gfcocos/autohotkey.git
git@gitee.com:gfcocos/autohotkey.git
gfcocos
autohotkey
autohotkey
master

搜索帮助