Search the Community
Showing results for tags 'count physical disk'.
-
;Count PHYSICAL Disk ;Physical disks, not drive letters Local $Cnt = 0, $iDrvNo = 0, $sPdisk = '\\.\PHYSICALDRIVE0' While 1 Local $sPdisk = '\\.\PHYSICALDRIVE' & $Cnt Local $iDrvNo = __WinAPI_GetDriveNumber($sPdisk) If $iDrvNo < $Cnt Then ExitLoop ConsoleWrite('Disk No: ' & $iDrvNo & @CRLF) $Cnt = $Cnt + 1 WEnd ConsoleWrite('PHYSICAL Disk Total: ' & $Cnt & @CRLF) Func __WinAPI_GetDriveNumber($sDrive) Local $hFile = ___CreateFile_OPEN_EXISTING($sDrive) If @error Then Return SetError(@error + 20, @extended, $hFile) Local $tSDN = DllStructCreate('dword;ulong;ulong') Local $aRet = DllCall('kernel32.dll', 'bool', 'DeviceIoControl', 'handle', $hFile, 'dword', 0x002D1080, 'ptr', 0, _ 'dword', 0, 'struct*', $tSDN, 'dword', DllStructGetSize($tSDN), 'dword*', 0, 'ptr', 0) If __CheckErrorCloseHandle($aRet, $hFile) Then Return SetError(@error, @extended, 0) Local $sResult = DllStructGetData($tSDN, 2) Return $sResult EndFunc ;==>__WinAPI_GetDriveNumber Func ___CreateFile_OPEN_EXISTING($sDrive) Local $hFile = DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sDrive, "dword", 0, "dword", 0, "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, "ptr", 0) If @error Or $hFile[0] = Ptr(-1) Then Return SetError(@error, @extended, 0) ; INVALID_HANDLE_VALUE Return $hFile[0] EndFunc Func __CheckErrorCloseHandle($aCall, $hFile, $bLastError = False, $iCurErr = @error, $iCurExt = @extended) If Not $iCurErr And Not $aCall[0] Then $iCurErr = 10 Local $aLastError = DllCall("kernel32.dll", "dword", "GetLastError") ; _WinAPI_GetLastError() DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hFile) If $iCurErr Then DllCall("kernel32.dll", "none", "SetLastError", "dword", $aLastError[0]) ; _WinAPI_SetLastError($iLastError) If $bLastError Then $iCurExt = $aLastError[0] Return SetError($iCurErr, $iCurExt, $iCurErr) EndFunc ;==>__CheckErrorCloseHandle Counts physical disks. Without letter and WMI