【已解决】关于如何动态获取磁盘的信息
本帖最后由 dgnanhua 于 2011-3-24 13:59 编辑如题:如何动态获取磁盘的信息? 琢磨了很久没得到解决,现求助于大家帮忙!
要求如下:
1.当没有外接磁盘时(U盘或移动硬盘),能显示列出当前本地硬盘信息及数量,
并在Combo1显示第一磁盘信息.
2.当插入外接磁盘时(U盘或移动硬盘),能显示列出所以磁盘信息及数量,
并在Combo1显示外接的第一磁盘信息.
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\磁盘.kxf
$Form1 = GUICreate("Form1", 332, 181, 192, 124)
$Group1 = GUICtrlCreateGroup("选择磁盘", 16, 24, 297, 81)
$Combo1 = GUICtrlCreateCombo("Combo1", 32, 56, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("刷新", 248, 56, 49, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("确定", 48, 128, 73, 25)
$Button3 = GUICtrlCreateButton("退出", 176, 128, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
经过haijie1223朋友的指导已经解决,在此谢谢帮助过我的朋友!谢谢! 第一个解答:安装完本坛汉化版后:D:\autoit3\Examples\GUI\GUI例子 - V10.au3从该AU3中能解决;
第二个解答:从本坛搜索里找,“监控USB插拔 ” 可解决; 回复 2# boyhong
这么快就有朋友帮忙解决,非常感谢你的热心!谢谢!
按你说的去看了下,还是没有解决.可能是我的帖了表达得不够准确,
要的功能就像下图中的这个:
自学能力很强,不错 我只会用WMI来获取硬盘的信息。从下边提你想要的信息。
__wmi_Win32_DiskDrive()
Func __wmi_Win32_DiskDrive()
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $colItems = ""
Local $strComputer = "localhost"
Local $Output=""
$Output &= "Computer: " & $strComputer& @CRLF
$Output &= "==========================================" & @CRLF
Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
For $objItem In $colItems
$Output &= "Availability: " & $objItem.Availability & @CRLF
$Output &= "BytesPerSector: " & $objItem.BytesPerSector & @CRLF
Local $strCapabilities = $objItem.Capabilities(0)
$Output &= "Capabilities: " & $strCapabilities & @CRLF
Local $strCapabilityDescriptions = $objItem.CapabilityDescriptions(0)
$Output &= "CapabilityDescriptions: " & $strCapabilityDescriptions & @CRLF
$Output &= "Caption: " & $objItem.Caption & @CRLF
$Output &= "CompressionMethod: " & $objItem.CompressionMethod & @CRLF
$Output &= "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
$Output &= "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
$Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF
$Output &= "DefaultBlockSize: " & $objItem.DefaultBlockSize & @CRLF
$Output &= "Description: " & $objItem.Description & @CRLF
$Output &= "DeviceID: " & $objItem.DeviceID & @CRLF
$Output &= "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
$Output &= "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
$Output &= "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF
$Output &= "Index: " & $objItem.Index & @CRLF
$Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
$Output &= "InterfaceType: " & $objItem.InterfaceType & @CRLF
$Output &= "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
$Output &= "Manufacturer: " & $objItem.Manufacturer & @CRLF
$Output &= "MaxBlockSize: " & $objItem.MaxBlockSize & @CRLF
$Output &= "MaxMediaSize: " & $objItem.MaxMediaSize & @CRLF
$Output &= "MediaLoaded: " & $objItem.MediaLoaded & @CRLF
$Output &= "MediaType: " & $objItem.MediaType & @CRLF
$Output &= "MinBlockSize: " & $objItem.MinBlockSize & @CRLF
$Output &= "Model: " & $objItem.Model & @CRLF
$Output &= "Name: " & $objItem.Name & @CRLF
$Output &= "NeedsCleaning: " & $objItem.NeedsCleaning & @CRLF
$Output &= "NumberOfMediaSupported: " & $objItem.NumberOfMediaSupported & @CRLF
$Output &= "Partitions: " & $objItem.Partitions & @CRLF
$Output &= "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
Local $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
$Output &= "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
$Output &= "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
$Output &= "SCSIBus: " & $objItem.SCSIBus & @CRLF
$Output &= "SCSILogicalUnit: " & $objItem.SCSILogicalUnit & @CRLF
$Output &= "SCSIPort: " & $objItem.SCSIPort & @CRLF
$Output &= "SCSITargetId: " & $objItem.SCSITargetId & @CRLF
$Output &= "SectorsPerTrack: " & $objItem.SectorsPerTrack & @CRLF
$Output &= "Signature: " & $objItem.Signature & @CRLF
$Output &= "Size: " & $objItem.Size & @CRLF
$Output &= "Status: " & $objItem.Status & @CRLF
$Output &= "StatusInfo: " & $objItem.StatusInfo & @CRLF
$Output &= "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
$Output &= "SystemName: " & $objItem.SystemName & @CRLF
$Output &= "TotalCylinders: " & $objItem.TotalCylinders & @CRLF
$Output &= "TotalHeads: " & $objItem.TotalHeads & @CRLF
$Output &= "TotalSectors: " & $objItem.TotalSectors & @CRLF
$Output &= "TotalTracks: " & $objItem.TotalTracks & @CRLF
$Output &= "TracksPerCylinder: " & $objItem.TracksPerCylinder & @CRLF
if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
$Output=""
Next
Else
Msgbox(0,"WMI 输出","没有在类 " & "Win32_DiskDrive" & "中找到WMI对象" )
Endif
EndFunc
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc 这个我曾经写过一个一模一样的好想和上面的不一样 本帖最后由 haijie1223 于 2011-3-24 11:04 编辑
楼主你用什么语言编写的gui好像不是au3 +我qq:29535065 回复 5# boyhong
非常感谢你的热心帮助!写法跟我想要的不一样.但还是要谢谢你.
我是一个新手,你给的方法也是一个傎得将来好好的学习. 回复 7# haijie1223
是用AU3写的.只不过可能写法不一样而已,
你写过类似的,那可以向你请教下!
页:
[1]