如何获取硬盘分区的编号?
不要依靠dsptw.exe。纯AU3,比如第一个硬盘第一分区1:1, 第二个硬盘2:1 .........
求例子 #include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
Opt('GUIOnEventMode', 1)
Global $aCtrlRange
$gui = GUICreate('磁盘信息管理', 500, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
$cm_Main = GUICtrlCreateContextMenu(-1)
GUICtrlCreateMenuItem('&Refresh', $cm_Main)
GUICtrlSetOnEvent(-1, '_Refresh')
$pg_Used = GUICtrlCreateProgress(0, 180, 380, 20, $PBS_SMOOTH)
GUICtrlSetColor(-1, 0xff)
$lb_UsedSh = GUICtrlCreateLabel('', 1, 181, 380, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0)
$lb_Used = GUICtrlCreateLabel('', 0, 180, 380, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xffffff)
GUICtrlCreateButton('打 开', 380, 180, 60, 20)
GUICtrlSetOnEvent(-1, '_Explore')
GUICtrlCreateButton('刷 新', 440, 180, 60, 20)
GUICtrlSetOnEvent(-1, '_Refresh')
$lv_Drives = GUICtrlCreateListView('盘符|卷标|类型|状态|文件系统|磁盘编号|可用空间|已使用空间|磁盘容量', 0, 0, 500, 180)
Opt('GUIDataSeparatorChar', @LF)
GUISetState()
$aCtrlRange = _ListView()
$iLvSel = 0
$iLvSelMem = -1
While 1
$iLvSel = _GUICtrlListView_GetNextItem($lv_Drives)
If $iLvSel <> -1 And $iLvSel <> $iLvSelMem Then
$sUsedSpace = _GUICtrlListView_GetItemText($lv_Drives, $iLvSel, 7)
$sUsedSpace = StringRegExpReplace($sUsedSpace, '.*\((\d+)%\)', '\1')
If Not @error And @extended Then
GUICtrlSetData($pg_Used, $sUsedSpace)
GUICtrlSetData($lb_Used, 'Used space (' & $sUsedSpace & '%)')
GUICtrlSetData($lb_UsedSh, 'Used space (' & $sUsedSpace & '%)')
Else
GUICtrlSetData($pg_Used, 0)
GUICtrlSetData($lb_Used, '')
GUICtrlSetData($lb_UsedSh, '')
EndIf
$iLvSelMem = $iLvSel
EndIf
Sleep(10)
WEnd
Func _Exit()
GUIDelete($gui)
Exit
EndFunc
Func _Refresh()
For $iCtrl = $aCtrlRange To $aCtrlRange
GUICtrlDelete($iCtrl)
Next
Global $aCtrlRange = _ListView()
EndFunc
Func _Explore()
$iLvSel = _GUICtrlListView_GetNextItem($lv_Drives)
If $iLvSel <> -1 Then
$sDrive = _GUICtrlListView_GetItemText($lv_Drives, $iLvSel, 0)
ShellExecute($sDrive)
EndIf
EndFunc
Func _ListView()
Local $aCtrlRange
$aCtrlRange = GUICtrlCreateDummy()
$aDrives = DriveGetDrive('all')
For $i = 1 To $aDrives
$sDrive = StringUpper($aDrives[$i])
$iTotalSpace = DriveSpaceTotal($sDrive)
If $iTotalSpace <= 0 Then
$sFreeSpace = '-'
$sUsedSpace = '-'
$sTotalSpace = '-'
Else
$sTotalByteAmt = 'MB'
$sFreeByteAmt = 'MB'
$sUsedByteAmt = 'MB'
$iFreeSpace = DriveSpaceFree($sDrive)
$iUsedSpace = $iTotalSpace - $iFreeSpace
$iFreePercent = 0
$iUsedPercent = 0
If $iTotalSpace > 0 Then
$iFreePercent = Round($iFreeSpace / $iTotalSpace * 100)
$iUsedPercent = 100 - $iFreePercent
EndIf
If $iTotalSpace > 1024 Then
$iTotalSpace /= 1024
$sTotalByteAmt = 'GB'
EndIf
If $iFreeSpace > 1024 Then
$iFreeSpace /= 1024
$sFreeByteAmt = 'GB'
EndIf
If $iUsedSpace > 1024 Then
$iUsedSpace /= 1024
$sUsedByteAmt = 'GB'
EndIf
$sTotalSpace = StringFormat('%.2f %s', $iTotalSpace, $sTotalByteAmt)
$sFreeSpace = StringFormat('%.2f %s (%d%%)', $iFreeSpace, $sFreeByteAmt, $iFreePercent)
$sUsedSpace = StringFormat('%.2f %s (%d%%)', $iUsedSpace, $sUsedByteAmt, $iUsedPercent)
EndIf
$sLabel = DriveGetLabel($sDrive)
If $sLabel = '' Then $sLabel = ''
GUICtrlCreateListViewItem( _
StringFormat('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s', _
$sDrive, _
$sLabel, _
DriveGetType($sDrive), _
DriveStatus($sDrive), _
DriveGetFileSystem($sDrive), _
DriveGetSerial($sDrive), _
$sFreeSpace, _
$sUsedSpace, _
$sTotalSpace), _
$lv_Drives)
Next
$aCtrlRange = GUICtrlCreateDummy()
Return $aCtrlRange
EndFunc 回复 2# ooxxgod
分区如果显示成 1:11:2这样的形式,要如何写? #include <WinApiEx.au3>
#include <array.au3>
Local $tSTORAGEDEVICENUMBER
Local $Drive = DriveGetDrive("FIXED")
If IsArray($Drive) Then
Local $List[$Drive]
For $i = 1 To $Drive
$tSTORAGEDEVICENUMBER = _WinAPI_GetDriveNumber($Drive[$i])
If Not @error Then
$List[$i-1] = StringUpper($Drive[$i])
$List[$i-1] = DllStructGetData($tSTORAGEDEVICENUMBER, 'DeviceNumber')+1 & ":" & DllStructGetData($tSTORAGEDEVICENUMBER, 'PartitionNumber')
EndIf
Next
_ArrayDisplay($List)
EndIf
页:
[1]