找回密码
 加入
搜索
查看: 3360|回复: 8

[AU3基础] 【已解决】关于如何动态获取磁盘的信息

  [复制链接]
发表于 2011-3-23 13:31:39 | 显示全部楼层 |阅读模式
本帖最后由 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
[/code]

经过haijie1223朋友的指导已经解决,在此谢谢帮助过我的朋友!谢谢!
发表于 2011-3-23 13:38:23 | 显示全部楼层
第一个解答:安装完本坛汉化版后:D:\autoit3\Examples\GUI\GUI例子 - V10.au3  从该AU3中能解决;
第二个解答:从本坛搜索里找,“监控USB插拔 ” 可解决;
 楼主| 发表于 2011-3-23 14:47:51 | 显示全部楼层
回复 2# boyhong


   
这么快就有朋友帮忙解决,非常感谢你的热心!谢谢!
按你说的去看了下,还是没有解决.可能是我的帖了表达得不够准确,
要的功能就像下图中的这个:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-3-23 20:46:24 | 显示全部楼层
自学能力很强,不错
发表于 2011-3-23 21:00:07 | 显示全部楼层
我只会用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
发表于 2011-3-24 10:50:48 | 显示全部楼层
这个我曾经写过一个一模一样的  好想和上面的不一样
发表于 2011-3-24 10:59:38 | 显示全部楼层
本帖最后由 haijie1223 于 2011-3-24 11:04 编辑

楼主你用什么语言编写的gui  好像不是au3   +我qq:29535065
 楼主| 发表于 2011-3-24 13:08:51 | 显示全部楼层
回复 5# boyhong

非常感谢你的热心帮助!写法跟我想要的不一样.但还是要谢谢你.
我是一个新手,你给的方法也是一个傎得将来好好的学习.
 楼主| 发表于 2011-3-24 13:10:35 | 显示全部楼层
回复 7# haijie1223


   
是用AU3写的.只不过可能写法不一样而已,
你写过类似的,那可以向你请教下!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 10:31 , Processed in 0.088274 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表