如何用au3获取本地硬盘的个数和大小?
本帖最后由 qixinwb 于 2010-1-30 10:56 编辑我的问题已经解决了。可是这个帖子删不了! 本帖最后由 pusofalse 于 2010-1-19 19:03 编辑
#include <SetupApi.au3>
Dim $hDevs, $tDevIfInfo, $tDevInfo, $sDevicePath, $iMask
Dim $sDescr, $iIndex, $tBuffer, $iPhysSize, $sResult
$tBuffer = DllStructCreate("int64 PhysicalSize")
$iMask = bitOR($DIGCF_PRESENT, $DIGCF_DEVICEINTERFACE)
$hDevs = _SetupDiGetClassDevs($iMask, $GUID_DEVINTERFACE_DISK)
$iMask = bitOR($GENERIC_READ, $GENERIC_WRITE)
While _SetupDiEnumDeviceInterfaces($hDevs, 0, $GUID_DEVINTERFACE_DISK, $iIndex, $tDevIfInfo)
$iIndex += 1
$sDevicePath = _SetupDiGetDeviceInterfaceDetail($hDevs, $tDevIfInfo, $tDevInfo)
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, 0xC)
If $sDescr = "" Then
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, 0)
EndIf
$sDevicePath = StringTrimLeft($sDevicePath, 4)
$sResult &= "Physical Drive #" & _CM_Get_Drive_Disk_Number($sDevicePath) & @Tab
$hFile = _CM_Create_File("\\?\" & $sDevicePath, $iMask, 3, 0, 3, 0)
_CM_Device_IO_Control($hFile, 0x7405C, 0, 0, $tBuffer, 8)
_CM_Close_Handle($hFile)
$iPhysSize = DllStructGetData($tBuffer, "PhysicalSize") / 1024 / 1024
$sResult &= $sDescr & @Tab & "(" & Round($iPhysSize, 1) & " MB)" & @CRLF
WEnd
_SetupDiApiBufferFree($tBuffer)
_SetupDiApiBufferFree($tDevInfo)
_SetupDiApiBufferFree($tDevIfInfo)
_SetupDiDestroyDeviceInfoList($hDevs)
Msgbox(0, "Physical Drive(s):", $sResult)
SetupApi.au3 - http://www.autoitx.com/forum.php?mod=viewthread&tid=10543&extra=page%3D1 错误: 不能打开包含文件 <SetupApi.au3> 回复 3# qixinwb
我想你应该先在论坛搜索一下,以"SetupApi.au3"为关键字。
或者,在搜不到的情况下,再看下重新编辑好的2#。 强大的pusofalse !
I 服了 U
无语中。。。。。。。。。。
不知何年何月才能望其项背啊! 感谢pusofalse老大的认真解答。小弟改造了一下,别怪我触犯您的版权哦:face (33):#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_outfile=本地硬盘信息.exe
#AutoIt3Wrapper_Res_Fileversion=0.0.0.0
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <SetupApi.au3>
Dim $hDevs, $tDevIfInfo, $tDevInfo, $sDevicePath, $iMask
Dim $sDescr, $iIndex, $tBuffer, $iPhysSize, $sResult
$tBuffer = DllStructCreate("int64 PhysicalSize")
$iMask = bitOR($DIGCF_PRESENT, $DIGCF_DEVICEINTERFACE)
$hDevs = _SetupDiGetClassDevs($iMask, $GUID_DEVINTERFACE_DISK)
$iMask = bitOR($GENERIC_READ, $GENERIC_WRITE)
While _SetupDiEnumDeviceInterfaces($hDevs, 0, $GUID_DEVINTERFACE_DISK, $iIndex, $tDevIfInfo)
$iIndex += 1
$sDevicePath = _SetupDiGetDeviceInterfaceDetail($hDevs, $tDevIfInfo, $tDevInfo)
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, 0xC)
If $sDescr = "" Then
$sDescr = _SetupDiGetDeviceRegistryProperty($hDevs, $tDevInfo, 0)
EndIf
$hFile = _CM_Create_File($sDevicePath, $iMask, 3, 0, 3, 0)
_CM_Device_IO_Control($hFile, 0x7405C, 0, 0, $tBuffer, 8)
_CM_Close_Handle($hFile)
$iPhysSize = DllStructGetData($tBuffer, "PhysicalSize") / 1024 / 1024
$sResult &= $sDescr & @Tab & Round($iPhysSize/954, 1) & " GB" & @CRLF
WEnd
_SetupDiApiBufferFree($tBuffer)
_SetupDiApiBufferFree($tDevInfo)
_SetupDiApiBufferFree($tDevIfInfo)
_SetupDiDestroyDeviceInfoList($hDevs)
IniWrite(@ScriptDir & "\空间.txt", "本地硬盘信息" , "", $sResult )
$cppf = DriveGetDrive("FIXED")
$sum=0
If Not @error Then
For $i = 1 To $cppf
Local $pf,$dif
$begin = TimerInit()
$pf = $cppf[$i]
$kj = DriveSpaceTotal($pf & "\") /954
$dif = TimerDiff($begin)
$kjz=Int($kj)
IniWrite(@ScriptDir & "\空间.txt", "磁盘空间" , $pf & "盘 全部空间为: ", $kjz &"GB")
$sum=$sum+$kj
Next
$sum1=Int($sum)
IniWrite(@ScriptDir & "\空间.txt", "磁盘空间" , "全部空间为: ", $sum1 &"GB")
EndIf
TrayTip("单击确定查看详细数据!","详细数据在此程序目录下的空间.txt中!",30,1)
$var=Msgbox(0, "本地硬盘信息:", $sResult)
If $var=1 Then
ShellExecute("空间.txt","",@ScriptDir)
EndIf 俺是菜鸟,不会API#include<array.au3>
$hd=DriveGetDrive("FIXED")
If IsArray($hd) Then
Local $hdsize[$hd+1]
$hdsize=$hd
For $i=1 To $hd
$hdsize[$i]= $hd[$i]
$hdsize[$i]=Round(DriveSpaceTotal($hd[$i])/1024,2) &' GB'
Next
_ArrayDisplay($hdsize)
EndIf
pusofalse 的代码永远是那么风骚。 pusofalse 的代码永远是那么风骚。
范统.贾 发表于 2010-1-20 07:48 http://www.autoitx.com/images/common/back.gif
【传送门:Au3 硬件设备管理UDF - SetupApi.au3】 新手一定要多搜索。。。。
页:
[1]