Page 1 sur 1
[..] Détecter si un disque est connecté en SATA ou en PATA
Posté : ven. 20 juil. 2012 14:35
par GhostLine
Salut les gens,
je cherche à savoir s'il est possible de remonter sur quel contrôleur est connecté un disque dur (SATA ou PATA [aka ATA-133]). Quelqu'un a-t-il déjà tenté cette manip' ?
Re: [..] Détecter si un disque est connecté en SATA ou en PA
Posté : ven. 20 juil. 2012 15:07
par timmalos
Ceci devrait vous donner la réponse:
Code : Tout sélectionner
;Généré par AutoIt ScriptOMatic
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$OutputTitle = ""
$Output = ""
$OutputTitle &= "Computer: " & $strComputer & @CRLF
$OutputTitle &= "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
Local $Object_Flag = 0
For $objItem In $colItems
$Object_Flag = 1
$Output &= "Availability: " & $objItem.Availability & @CRLF
$Output &= "BytesPerSector: " & $objItem.BytesPerSector & @CRLF
$strCapabilities = $objItem.Capabilities(0)
$Output &= "Capabilities: " & $strCapabilities & @CRLF
$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 &= "FirmwareRevision: " & $objItem.FirmwareRevision & @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
$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 &= "SerialNumber: " & $objItem.SerialNumber & @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,"Sortie WMI",$Output) = 2 then ExitLoop
$Output=""
Next
If $Object_Flag = 0 Then Msgbox(1,"Sortie WMI",$OutputTitle)
Else
Msgbox(0,"Sortie WMI","Aucun objets WMI trouvés pour la Classe :" & "Win32_DiskDrive" )
Endif
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
Re: [..] Détecter si un disque est connecté en SATA ou en PA
Posté : ven. 20 juil. 2012 15:12
par timmalos
Sinon, ceci
Code : Tout sélectionner
Local $Drive = DriveGetDrive('ALL')
For $i = 1 To $Drive[0]
ConsoleWrite(StringUpper($Drive[$i]) & ' => ' & _DriveGetBusType(StringLeft($Drive[$i], 1)) & @CR)
Next
Func _DriveGetBusType($DriveLetter)
Local $Ret
$Ret = DllCall('kernel32.dll', 'hwnd', 'CreateFile', _
'str', '\\.\' & $DriveLetter & ':', _
'dword', 0, _
'dword', 0, _
'ptr', 0, _
'dword', 3, _
'dword', 128, _
'ptr', 0 _
)
If @error Then
Return SetError(1, 0, -1)
EndIf
If $Ret[0] = 0xFFFFFFFF Then
Return SetError(2, 0, -1)
EndIf
Local $tSTORAGE_PROPERTY_QUERY = DllStructCreate('dword;dword;byte[4]')
Local $tSTORAGE_DEVICE_DESCRIPTOR = DllStructCreate('ulong;ulong;byte;byte;byte;byte;ulong;ulong;ulong;ulong;dword;ulong;byte[512]')
Local $hDevice = $Ret[0]
$Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _
'hwnd', $hDevice, _
'dword', 0x002D1400, _
'ptr', DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), _
'dword', DllStructGetSize($tSTORAGE_PROPERTY_QUERY), _
'ptr', DllStructGetPtr($tSTORAGE_DEVICE_DESCRIPTOR), _
'dword', DllStructGetSize($tSTORAGE_DEVICE_DESCRIPTOR), _
'dword*', 0, _
'ptr', 0 _
)
If (@error) Or ($Ret[0] = 0) Then
$Ret = -1
Else
Switch DllStructGetData($tSTORAGE_DEVICE_DESCRIPTOR, 11)
Case 0x00
$Ret = 'UNKNOWN' ; Unknown bus type
Case 0x01
$Ret = 'SCSI' ; Small computer system interface (SCSI)
Case 0x02
$Ret = 'ATAPI' ; AT Attachment Packet Interface (ATAPI)
Case 0x03
$Ret = 'ATA' ; Advanced technology attachment (ATA)
Case 0x04
$Ret = '1394' ; IEEE 1394
Case 0x05
$Ret = 'SSA' ; Serial storage architecture (SSA)
Case 0x06
$Ret = 'FIBRE' ; Fibre channel
Case 0x07
$Ret = 'USB' ; USB
Case 0x08
$Ret = 'RAID' ; Redundant array of independent disks (RAID)
Case 0x09
$Ret = 'ISCSI' ; iSCSI
Case 0x0A
$Ret = 'SAS' ; Serial-attached SCSI
Case 0x0B
$Ret = 'SATA' ; Serial ATA
Case 0x0C
$Ret = 'SD' ; Secure digital
Case 0x0D
$Ret = 'MMC' ; Multimedia card
EndSwitch
EndIf
DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $hDevice)
Return SetError(3 * ($Ret < 0), 0, $Ret)
EndFunc ;==>_DriveGetBusType
Re: [R] Détecter si un disque est connecté en SATA ou en PATA
Posté : ven. 29 juil. 2016 21:04
par Boulanza
Bonjour Timmalos,
S’il vous plaît Timmalos je souhaiterai si c'est possible de m’aider à ajouter une condition sur votre script :
Si
«
If (@error) Or ($Ret[0] = 0) Then $Ret = -1 »
alors exécuter ma fonction :
MonterImageIso()
Merci d’avance pour votre aide.
Cordialement.
Local $Drive = DriveGetDrive('CDROM')Global $RetFor $i = 1 To $Drive[0] ConsoleWrite(StringUpper($Drive[$i]) & ' => ' & _DriveGetBusType
(StringLeft($Drive[$i], 1)) & @CR)NextFunc _DriveGetBusType
($DriveLetter) Local $Ret $Ret = DllCall('kernel32.dll', 'hwnd', 'CreateFile', _
'str', '\\.\' & $DriveLetter & ':', _
'dword', 0, _
'dword', 0, _
'ptr', 0, _
'dword', 3, _
'dword', 128, _
'ptr', 0 _
) If @error Then Return SetError(1, 0, -1) EndIf If $Ret[0] = 0xFFFFFFFF Then Return SetError(2, 0, -1) EndIf Local $tSTORAGE_PROPERTY_QUERY = DllStructCreate('dword;dword;byte[4]') Local $tSTORAGE_DEVICE_DESCRIPTOR = DllStructCreate('ulong;ulong;byte;byte;byte;byte;ulong;ulong;ulong;ulong;dword;ulong;byte[512]') Local $hDevice = $Ret[0] $Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _
'hwnd', $hDevice, _
'dword', 0x002D1400, _
'ptr', DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), _
'dword', DllStructGetSize($tSTORAGE_PROPERTY_QUERY), _
'ptr', DllStructGetPtr($tSTORAGE_DEVICE_DESCRIPTOR), _
'dword', DllStructGetSize($tSTORAGE_DEVICE_DESCRIPTOR), _
'dword*', 0, _
'ptr', 0 _
) If (@error) Or ($Ret[0] = 0) Then $Ret = "VirtuelDrive" ;-1 Else Switch DllStructGetData($tSTORAGE_DEVICE_DESCRIPTOR, 11) Case 0x02 $Ret = 'ATAPI' ; AT Attachment Packet Interface (ATAPI) EndSwitch EndIf Return SetError(3 * ($Ret < 0), 0, $Ret)EndFunc ;==>_DriveGetBusType
Re: [..] Détecter si un disque est connecté en SATA ou en PATA
Posté : ven. 29 juil. 2016 22:50
par Boulanza
Bonsoir,
Je me déteste lorsque je perds mes capacités de se souvenir des choses, en plus sous une température de 45° à l’ambre... Et pourtant la solution était évidente :
If (@error) Or ($Ret[0] = 0) Then
$Ret = -1 ;"VirtuelDrive"
MsgBox(64,"Fotoimport", StringUpper($Drive[$i]))
je vous prie d'excuser cette confusion de ma part. Merci
Cordialement.