Bah finalement, j'ai réussi à la faire fonctionner, il indique bien le modèle du disque.
Code : Tout sélectionner
;/////////////////////////////////////////////////////////////// ;
;// Disk Drive WMI With ComatePlus For 4.5x Example //
;// jpd //
;// Date September 2008 Update October 2010 PB 4.51 //
;///////////////////////////////////////////////////////////
Enumeration
#DiskNr
#List_partition
#Check_USB
EndEnumeration
IncludeFile "COMatePlus.pbi"
Structure PartitionInfo
Partition.s
DriveLetter.s
FileSystem.s
FreeSpace.s
Size.s
VolumeName.s
VolumeSerialNumber.s
Bootable.l
BootPartition.l
PrimaryPartition.l
Type.s
EndStructure
Structure DiskInfo
DiskNr.s
PartNr.PartitionInfo
DeviceID.s
PNPDeviceID.s
FirmwareRevision.s
InterfaceType.s
MediaType.s
Model.s
Status.s
EndStructure
Global NewList info.DiskInfo()
Procedure Partition_To_DiskDrive(devID.s)
;Define.COMateObject
objWMIService.COMateObject
USBCfg.COMateObject
EnumUSB.COMateObject
strComputer.s = "."
objWMIService.COMateObject = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
EnumUSBset.COMateEnumObject
x=0
Debug devID
EnumUSBset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_DiskDrive Where DeviceID= $0027" + devID +"$0027')")
Debug COMate_GetLastErrorCode()
Debug COMate_GetLastErrorDescription()
If EnumUSBset
EnumUSB = EnumUSBset\GetNextObject()
While EnumUSB
If EnumUSB
Debug x
Debug "Description: "+EnumUSB\GetstringProperty("Description")
info()\FirmwareRevision=EnumUSB\GetstringProperty("FirmwareRevision")
info()\InterfaceType=EnumUSB\GetstringProperty("InterfaceType")
info()\MediaType=EnumUSB\GetstringProperty("MediaType")
info()\Model=EnumUSB\GetstringProperty("Model")
info()\PNPDeviceID=EnumUSB\GetstringProperty("PNPDeviceID")
info()\Status=EnumUSB\GetstringProperty("Status")
EnumUSB\Release()
x=x+1
EndIf
EnumUSB = EnumUSBset\GetNextObject()
Wend
EnumUSBset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure Win32_DiskDrivePhysicalMedia()
;Define.COMateObject
objWMIService.COMateObject
EnumDiskDrive.COMateObject
EnumDiskDriveset.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
x=0
EnumDiskDriveset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_DiskDrivePhysicalMedia')")
If EnumDiskDriveset
EnumDiskDrive = EnumDiskDriveset\GetNextObject()
While EnumDiskDrive
If EnumDiskDrive
physdrive.l=FindString(EnumDiskDrive\GetstringProperty("Antecedent"),"\\\\.\\PHYSICALDRIVE",1)
If physdrive
diskpart.s=RemoveString(Mid(EnumDiskDrive\GetstringProperty("Antecedent"),physdrive,Len("\\\\.\\PHYSICALDRIVE")+2),Chr(34))
Partition_To_DiskDrive(diskpart)
EndIf
EndIf
EnumDiskDrive = EnumDiskDriveset\GetNextObject()
Wend
EnumDiskDriveset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure.s Diskpartition(diskpart.s)
found.l= FindString(diskpart,Chr(34),1)
ProcedureReturn Mid(diskpart,found,Len(diskpart)-found+1)
EndProcedure
Procedure LogicalDiskToPartition(antecedent.s)
;Define.COMateObject
objWMIService.COMateObject
EnumLDisk.COMateObject
EnumLDiskset.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
x=0
antecedent=ReplaceString(antecedent, "\", "\\")
EnumLDiskset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_LogicalDiskToPartition Where Antecedent= $0027" + antecedent +"$0027')")
If EnumLDiskset
EnumLDisk = EnumLDiskset\GetNextObject()
While EnumLDisk
If EnumLDisk
driveletter.s=EnumLDisk\GetstringProperty("Dependent")
info()\PartNr\DriveLetter=RemoveString(diskpartition(driveletter),Chr(34))
EnumLDisk\Release()
EndIf
EnumLDisk = EnumLDiskset\GetNextObject()
Wend
EnumLDiskset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure Win32_DiskDriveToDiskPartition()
; Define.COMateObject
objWMIService.COMateObject
EnumDisk.COMateObject
EnumDiskset.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
x=0
EnumDiskset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_DiskDriveToDiskPartition')")
If EnumDiskset
EnumDisk = EnumDiskset\GetNextObject()
While EnumDisk
If EnumDisk
Debug x
AddElement(Info())
diskpart.s= EnumDisk\GetstringProperty("Dependent")
LogicalDiskToPartition(diskpart)
diskpartition(diskpart)
For xx=1 To CountString(diskpartition(diskpart),",")+1
Ergebnis$ = StringField(diskpartition(diskpart), xx, ",")
Ergebnis$= RemoveString(Ergebnis$,Chr(34))
If xx=1
Info()\DiskNr=Ergebnis$
Debug "Disk Nr: "+Ergebnis$
If tmp$<>Ergebnis$
Debug "DisktoCheck: "+Ergebnis$
tmp$=Ergebnis$
diskNr.s=RemoveString(tmp$,"Disk #")
Debug DiskNr
EndIf
y=x
Else
Debug "Partition Nr: "+Ergebnis$
Info()\PartNr\Partition=Ergebnis$
y=x
x=x+1
EndIf
Next
physdrive.l=FindString(EnumDisk\GetstringProperty("Antecedent"),"\\\\.\\PHYSICALDRIVE",1)
If physdrive
diskpart.s=RemoveString(Mid(EnumDisk\GetstringProperty("Antecedent"),physdrive,Len("\\\\.\\PHYSICALDRIVE")+2),Chr(34))
Debug diskpart
If tmpdisk$<>diskpart
tmpdisk$=diskpart
Info()\DeviceID=EnumDisk\GetstringProperty("Antecedent")
Partition_To_DiskDrive(diskpart)
EndIf
EndIf
EndIf
EnumDisk = EnumDiskset\GetNextObject()
Wend
EnumDiskset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure Win32_DiskPartition(DeviceID.s)
;Define.COMateObject
objWMIService.COMateObject
EnumPart.COMateObject
EnumPartset.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
x=0
EnumPartset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_DiskPartition Where DeviceID= $0027" + DeviceID +"$0027')")
If EnumPartset
EnumPart = EnumPartset\GetNextObject()
While EnumPart
If EnumPart
Info()\PartNr\Bootable=EnumPart\GetIntegerProperty("Bootable")
Info()\PartNr\BootPartition=EnumPart\GetIntegerProperty("BootPartition")
Info()\PartNr\PrimaryPartition=EnumPart\GetIntegerProperty("PrimaryPartition")
Info()\PartNr\Type=EnumPart\GetstringProperty("Type")
EndIf
EnumPart = EnumPartset\GetNextObject()
Wend
EnumPartset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure.s DiskSpace(strval.s)
Protected lpTotalNumberOfBytes.q, res.f, CapStr.s
lpTotalNumberOfBytes=Val(strval.s)
res= lpTotalNumberOfBytes/(1024*1024*1024)
CapStr= StrD(res,2)
ProcedureReturn CapStr
EndProcedure
Procedure Win32_LogicalDisk(Driveletter.s)
;Define.COMateObject
objWMIService.COMateObject
EnumDrive.COMateObject
EnumDriveset.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
x=0
EnumDriveset = objWMIService\CreateEnumeration("ExecQuery('Select * From Win32_LogicalDisk Where Caption= $0027" + Driveletter +"$0027')")
If EnumDriveset
EnumDrive = EnumDriveset\GetNextObject()
While EnumDrive
If EnumDrive
Debug x
Debug EnumDrive\GetstringProperty("Caption")
Info()\PartNr\FileSystem=EnumDrive\GetstringProperty("FileSystem")
Info()\PartNr\FreeSpace=DiskSpace(EnumDrive\GetstringProperty("FreeSpace"))
Info()\PartNr\Size=DiskSpace(EnumDrive\GetstringProperty("Size"))
Info()\PartNr\VolumeName=EnumDrive\GetstringProperty("VolumeName")
Info()\PartNr\VolumeSerialNumber= EnumDrive\GetstringProperty("VolumeSerialNumber")
EndIf
EnumDrive = EnumDriveset\GetNextObject()
Wend
EnumDriveset\Release()
EndIf
objWMIService\Release()
EndIf
EndProcedure
Procedure Start()
ClearList(Info())
ClearGadgetItems(#List_partition)
ClearGadgetItems(#DiskNr)
Win32_DiskDriveToDiskPartition()
ResetList(Info())
x=0
While NextElement(Info())
Win32_LogicalDisk(Info()\PartNr\Driveletter)
Win32_DiskPartition(Info()\DiskNr+","+Info()\partNr\Partition)
If tmpdisk.s <>Info()\DiskNr
If Info()\InterfaceType <> "" And GetGadgetState(#Check_USB)=0
AddGadgetItem(#DiskNr, -1, Info()\DiskNr)
SetGadgetItemText(#DiskNr, x, Info()\InterfaceType,1)
SetGadgetItemText(#DiskNr, x, Info()\MediaType,2)
SetGadgetItemText(#DiskNr, x, Info()\Model,3)
SetGadgetItemText(#DiskNr, x, Info()\DeviceID,4)
SetGadgetItemText(#DiskNr, x, Info()\PNPDeviceID,5)
SetGadgetItemText(#DiskNr, x, Info()\FirmwareRevision,6)
SetGadgetItemText(#DiskNr, x, Info()\Status,7)
x=x+1
tmpdisk.s =Info()\DiskNr
ElseIf Info()\InterfaceType = "USB" And GetGadgetState(#Check_USB)=1
AddGadgetItem(#DiskNr, -1, Info()\DiskNr)
SetGadgetItemText(#DiskNr, x, Info()\InterfaceType,1)
SetGadgetItemText(#DiskNr, x, Info()\MediaType,2)
SetGadgetItemText(#DiskNr, x, Info()\Model,3)
SetGadgetItemText(#DiskNr, x, Info()\DeviceID,4)
SetGadgetItemText(#DiskNr, x, Info()\PNPDeviceID,5)
SetGadgetItemText(#DiskNr, x, Info()\FirmwareRevision,6)
SetGadgetItemText(#DiskNr, x, Info()\Status,7)
x=x+1
EndIf
EndIf
Wend
EndProcedure
If OpenWindow(0, 100, 100, 800, 550, "Disk Drive", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#DiskNr, 5, 5, 790, 250, "DiskNr", 80, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#DiskNr, 1, "InterfaceType", 50)
AddGadgetColumn(#DiskNr, 2, "MediaType", 100)
AddGadgetColumn(#DiskNr, 3, "Model", 100)
AddGadgetColumn(#DiskNr, 4, "DeviceID", 100)
AddGadgetColumn(#DiskNr, 5, "PNPDeviceID", 100)
AddGadgetColumn(#DiskNr, 6, "FirmwareRevision", 100)
AddGadgetColumn(#DiskNr, 7, "Status", 100)
ListIconGadget(#List_partition, 5, 260, 790, 250, "Partition", 80, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#List_partition, 1, "DriveLetter", 40)
AddGadgetColumn(#List_partition, 2, "FileSystem", 50)
AddGadgetColumn(#List_partition, 3, "Size Gb:", 60)
AddGadgetColumn(#List_partition, 4, "FreeSpace Gb:", 60)
AddGadgetColumn(#List_partition, 5, "FreeSpace %:", 50)
AddGadgetColumn(#List_partition, 6, "VolumeName", 100)
AddGadgetColumn(#List_partition, 7, "VolumeSerialNumber", 80)
AddGadgetColumn(#List_partition, 8, "Bootable", 40)
AddGadgetColumn(#List_partition, 9, "BootPartition", 40)
AddGadgetColumn(#List_partition, 10, "PrimaryPartition", 40)
AddGadgetColumn(#List_partition, 11, "Type", 100)
CheckBoxGadget(#Check_USB,5,520,150,20,"View only USB Device")
EndIf
start()
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #Check_USB
If GetGadgetState(#Check_USB)
Debug "check"
start()
Else
Debug "Uncheck"
start()
EndIf
Case #DiskNr
Debug GetGadgetState(#DiskNr)
ResetList(info())
ClearGadgetItems(#List_partition)
x=0
While NextElement(Info())
If Info()\DiskNr=GetGadgetItemText(#DiskNr, GetGadgetState(#DiskNr))
AddGadgetItem(#List_partition, -1, info()\partNr\Partition)
SetGadgetItemText(#List_partition, x, Info()\PartNr\Driveletter,1)
SetGadgetItemText(#List_partition, x, Info()\PartNr\FileSystem,2)
SetGadgetItemText(#List_partition, x, Info()\PartNr\FreeSpace,4)
SetGadgetItemText(#List_partition, x, Info()\PartNr\Size,3)
procent.s=StrD((ValF(Info()\PartNr\FreeSpace)*100)/ValF(Info()\PartNr\Size),2)+" %"
SetGadgetItemText(#List_partition, x, procent,5)
SetGadgetItemText(#List_partition, x, Info()\PartNr\VolumeName,6)
SetGadgetItemText(#List_partition, x, Info()\PartNr\VolumeSerialNumber,7)
SetGadgetItemText(#List_partition, x, RemoveString(Str(Info()\PartNr\Bootable),"-"),8)
SetGadgetItemText(#List_partition, x, RemoveString(Str(Info()\PartNr\BootPartition),"-"),9)
SetGadgetItemText(#List_partition, x, RemoveString(Str(Info()\PartNr\PrimaryPartition),"-"),10)
SetGadgetItemText(#List_partition, x, Info()\PartNr\Type,11)
x=x+1
EndIf
Wend
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow