Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detect SSD drive
Message
 
To
26/12/2017 05:51:59
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01656676
Message ID:
01656722
Views:
58
>Thanks Yousfi for your comprehensive sample program
>
>I get an OLE error ("Name can't open the file") on
>
>oWMI = Getobject("WINMGMTS:\\.\ROOT\Microsoft\Windows\Storage")
>
>
>This works fine:
>
>oWMI = Getobject("WINMGMTS:\\.\ROOT\Cimv2")
>
>
>However, all of these fail:
>
>win = oWMI.instancesof("MSFT_PhysicalDisk")
>? win.Count && OLE error: invalid class
>win = oWMI.InstancesOf("MSFT_PhysicalDisk", 1) && OLE error: invalid class
>
>win = oWMI.instancesof("MSFT_VirtualDisk")
>? win.Count && same error
>
>win = oWMI.instancesof("MSFT_Disk")
>? win.Count && same error
>
>
>What could I try next?
>
>
>>Hi Thierry
>>try this code made with wmi
>>
>>*adapted from http://wutils.com/wmi/root/microsoft/windows/storage/msft_physicaldisk/vbscript-samples.html
>>*can try other properties of  MSFT_PhysicalDisk class
>>
>>Create Cursor ycurs (allocateSize c(20),mediaType c(2), FriendlyName c(20),PhysicalLocation c(20),Size c(20),healthStatus c(2)  )
>>
>>Local oWMI, Instances, Instance
>>*Get base WMI object, "." means computer name (local)
>>oWMI = Getobject("WINMGMTS:\\.\ROOT\Microsoft\Windows\Storage")
>>*Get instances of MSFT_PhysicalDisk - all instances of this class and derived classes
>>Instances = oWMI.InstancesOf("MSFT_PhysicalDisk")
>>*Get instances of MSFT_PhysicalDisk
>>Instances = oWMI.InstancesOf("MSFT_PhysicalDisk", 1)
>>
>>*Enumerate instances
>>For Each Instance In Instances
>>  *Do something with the instance
>>  Insert Into ycurs Values (;
>>    trans(Instance.AllocatedSize),;
>>    trans(Instance.mediaType),;
>>    Instance.FriendlyName,;
>>    Instance.PhysicalLocation,;
>>    trans(Instance.Size),;
>>    trans(Instance.healthStatus);
>>    )
>>
>>Next  &&Instance
>>Brow
>>
>>*!*	MediaType
>>*!*	    Data type: UInt16
>>*!*	    Access type: Read-only
>>*!*	    The media type of the physical disk.
>>*!*	    Value	Meaning
>>*!*	    0          Unspecified
>>*!*	    3          HDD
>>*!*	    4          SSD
>>*!*	    5          SCM
>>
>>
>>for SSD definition: http://searchstorage.techtarget.com/definition/SSD-solid-state-drive
strComputer = "."
objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    ?"DeviceID: "+ objDisk.DeviceID       
    DO case

        CASE objDisk.DriveType= 1
            ? "No root directory. " + "Drive type could not be " + "determined."
        Case objDisk.DriveType=2
            ? "DriveType: " +  "Removable drive."
        Case objDisk.DriveType=3
           ? "DriveType: "+  "Local hard disk."
        CASE objDisk.DriveType= 4
            ? "DriveType: " +  "Network disk."      
        CASE objDisk.DriveType= 5
            ? "DriveType: " +  "Compact disk."      
        CASE objDisk.DriveType= 6
            ? "DriveType: "+   "RAM disk."   
        OTHERWISE 
            ? "Drive type could not be" + " determined."
    EndCase
ENDFOR
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform