TestPc Posted January 23, 2021 Share Posted January 23, 2021 (edited) expandcollapse popup;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 Edited January 24, 2021 by TestPc added codebox Link to comment Share on other sites More sharing options...
Nine Posted January 23, 2021 Share Posted January 23, 2021 Or : Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT Caption FROM Win32_DiskDrive') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object") ConsoleWrite ("Count = " & $colItems.count & @CRLF) For $item in $colItems ConsoleWrite ("Caption = " & $item.caption & @CRLF) Next “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Musashi Posted January 23, 2021 Share Posted January 23, 2021 5 hours ago, TestPc said: Counts physical disks, not drive letters. No, it only provides errors : (9,21) : error: ListPart(): undefined function. (18,52) : error: _WinAPI_CreateFile(): undefined function. ==> #include <WinAPI.au3> is missing(24,45) : error: __CheckErrorCloseHandle(): undefined function. It seems, that you copied your code from a larger script and thereby missed important parts. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted January 23, 2021 Share Posted January 23, 2021 People who are interested in this topic might find the following thread helpful : get-disk-number-from-drive-letter (from @PsaltyDS) $oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $colDiskDrives = $oWMISvc.ExecQuery("SELECT * FROM Win32_DiskDrive") For $oDiskDrive In $colDiskDrives ConsoleWrite("DiskDrive = " & $oDiskDrive.DeviceId & " Caption = " & $oDiskDrive.Caption & @LF) $sQuery = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $oDiskDrive.DeviceId & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" $colPartitions = $oWMISvc.ExecQuery($sQuery) For $oPartition In $colPartitions ConsoleWrite(@TAB & "Partition = " & $oPartition.DeviceId & @LF) $sQuery = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $oPartition.DeviceId & "'} WHERE AssocClass = Win32_LogicalDiskToPartition" $colLogicalDisks = $oWMISvc.ExecQuery($sQuery) For $oLogicalDisk In $colLogicalDisks ConsoleWrite(@TAB & @TAB & "LogicalDisk = " & $oLogicalDisk.DeviceId & @LF) Next Next Next Also have a look at the subsequent contributions from @trancexx . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Gianni Posted January 23, 2021 Share Posted January 23, 2021 ; by AutoIt native function MsgBox(0,'Num of Drives', DriveGetDrive('ALL')[0]) ; by FileSystemObject ; https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object MsgBox(0,'Num of Drives',ObjCreate("Scripting.FileSystemObject").Drives.Count) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
TestPc Posted January 24, 2021 Author Share Posted January 24, 2021 12 hours ago, Musashi said: No, it only provides errors : (9,21) : error: ListPart(): undefined function. (18,52) : error: _WinAPI_CreateFile(): undefined function. ==> #include <WinAPI.au3> is missing(24,45) : error: __CheckErrorCloseHandle(): undefined function. It seems, that you copied your code from a larger script and thereby missed important parts. ok. Modification complete. Link to comment Share on other sites More sharing options...
RTFC Posted January 24, 2021 Share Posted January 24, 2021 Since everybody is pitching in, here's an MBR-based approach. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now