It is currently October 14th, 2024, 11:35 pm

[SOLVED] measure FreeDiskSpace option Type question

General topics related to Rainmeter.
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

[SOLVED] measure FreeDiskSpace option Type question

Post by nmdelrio »

Code: Select all

[DriveType]
Measure=FreeDiskSpace
Drive=D:
Type=1

When I plug in a USB flash drive, [DriveType] returns the string "Removable", and when I plug in a USB hard disk also returns the string "Fixed".

Shouldn't plugging the USB hard disk also return the string "Removeable" because it is also removable ? What am I missing in my script ?

Any input is appreciated. Thank you.
Last edited by nmdelrio on April 17th, 2023, 12:02 am, edited 2 times in total.
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: measure FreeDiskSpace option Type question

Post by Yincognito »

nmdelrio wrote: April 16th, 2023, 9:34 am

Code: Select all

[DriveType]
Measure=FreeDiskSpace
Drive=D:
Type=1

When I plug in a USB flash drive, [DriveType] returns the string "Removable", and when I plug in a USB hard disk also returns the string "Fixed".

Shouldn't plugging the USB hard disk also return the string "Removeable" because it is also removable ? What am I missing in my script ?

Any input is appreciated. Thank you.
In theory, yes, but it probably has to do with how Microsoft classifies stuff in this case. Rainmeter gets the drive type like this, and the said function is explained here. In other words, it's probably more about the type of the drive (i.e. a HDD, aka "fixed") than the type of connection (i.e. USB, aka "removable").

That being said, you can interrogate what you want in other ways too, one of which is using PowerShell (it probably works from CMD too via WMIC):

Code: Select all

[MS_RunCommand_DisksInfo]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=-command gcim -classname Win32_DiskDrive -filter \"DeviceID like '%PHYSICALDRIVE%'\" | select InterfaceType,Manufacturer,MediaType,Model,Partitions,@{n='Size';e={[string][math]::round($_.Size/1GB,2)}} | sort Index | format-list
State=Hide
OutputType=ANSI
Timeout=10000
DynamicVariables=1
The above (quote unescaped) command in PS, i.e.

Code: Select all

gcim -classname Win32_DiskDrive -filter "DeviceID like '%PHYSICALDRIVE%'" | select InterfaceType,Manufacturer,MediaType,Model,Partitions,@{n='Size';e={[string][math]::round($_.Size/1GB,2)}} | sort Index | format-list
returns for me this:
Media Type.jpg
where the first is one of my USB hard disks I just plugged in for testing.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2746
Joined: March 23rd, 2015, 5:26 pm

Re: measure FreeDiskSpace option Type question

Post by SilverAzide »

nmdelrio wrote: April 16th, 2023, 9:34 am

Code: Select all

[DriveType]
Measure=FreeDiskSpace
Drive=D:
Type=1

When I plug in a USB flash drive, [DriveType] returns the string "Removable", and when I plug in a USB hard disk also returns the string "Fixed".

Shouldn't plugging the USB hard disk also return the string "Removeable" because it is also removable ? What am I missing in my script ?

Any input is appreciated. Thank you.
You are not missing anything. If I recall correctly, this is actually what the firmware of the USB drive is reporting to Windows. I thought I read something a long time ago that changing the drive properties to "quick removal" (if possible) will fix this, but if your USB device is a mechanical hard drive, I would suggest not doing that otherwise you will lose data if you don't do the "safely remove hardware" before unplugging.

The best way to determine the actual type of drive is not using the drive type from Rainmeter. You can use PowerShell commands like Get-Disk or Get-PhysicalDisk to look at the BusType, like so:

Code: Select all

PS > Get-PhysicalDisk | Select-Object DeviceId, MediaType, BusType | Sort-Object -Property DeviceId | Format-Table

DeviceId MediaType   BusType
-------- ---------   -------
0        SSD         NVMe
1        SSD         NVMe
2        HDD         SATA
3        HDD         SATA
4        HDD         SATA
5        HDD         SATA
8        Unspecified USB
You'll need to do some additional work if you want to fetch this info by it's logical disk name (i.e., "drive letter").

P.S.: In case it is not clear, you'd use a RunCommand measure to fetch this info.
Gadgets Wiki GitHub More Gadgets...
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

Re: measure FreeDiskSpace option Type question

Post by nmdelrio »

OMG! :jawdrop :o Thank you both but all these Powershell commands are Klingon to me.

For my intentions, knowing just the InterfaceType for any selected specific drive N: would alone allow me to get some sleep. :D Can you be kind enough to tell me what command shall be? :confused:

Though I have been scripting Rainmeter for some time now doing simple system monitoring skins using HWInfo plugin, RunCommand is one plugin I never used because I do not know what to put in Parameter.

@balala, roger that. Thanks for letting me know. :thumbup:
User avatar
SilverAzide
Rainmeter Sage
Posts: 2746
Joined: March 23rd, 2015, 5:26 pm

Re: measure FreeDiskSpace option Type question

Post by SilverAzide »

nmdelrio wrote: April 16th, 2023, 7:46 pm OMG! :jawdrop :o Thank you both but all these Powershell commands are Klingon to me.

For my intentions, knowing just the InterfaceType for any selected specific drive N: would alone allow me to get some sleep. :D Can you be kind enough to tell me what command shall be? :confused:

Though I have been scripting Rainmeter for some time now doing simple system monitoring skins using HWInfo plugin, RunCommand is one plugin I never used because I do not know what to put in Parameter.

@balala, roger that. Thanks for letting me know. :thumbup:
Getting the InterfaceType for your drive probably isn't going to help you in this case, because -- based the issue in your original post -- it most likely will return the same thing as a fixed disk drive. (It does for me, anyway.) You need the BusType value.

You can use something like this to get the drive bus type by drive letter:

Code: Select all

[MeasureDriveType]
Measure=Plugin
Plugin=RunCommand
Program=powershell.exe
Parameter="-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "Get-Partition -DriveLetter 'C' | Get-Disk | Select-Object BusType | Format-Table -AutoSize -HideTableHeaders""
OutputType=ANSI
State=Hide
Timeout=5000
Substitute="#CRLF#":""

; Value                Meaning
; ===================  ======================================
; Unknown              The bus type is unknown.
; SCSI                 SCSI
; ATAPI                ATAPI
; ATA                  ATA
; 1394                 IEEE 1394
; SSA                  SSA
; Fibre Channel        Fibre Channel
; USB                  USB
; RAID                 RAID
; iSCSI                iSCSI
; SAS                  Serial Attached SCSI (SAS)
; SATA                 Serial ATA (SATA)
; SD                   Secure Digital (SD)
; MMC                  Multimedia Card (MMC)
; MAX                  This value is reserved for system use.
; File Backed Virtual  File-Backed Virtual
; Spaces               Storage Spaces
; NVMe                 NVMe
; Microsoft Reserved   This value is reserved for system use.
;
; see https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-physicaldisk
;
To use this measure, you need to run it. One simple way to do this is to include code in your [Rainmeter] section:

Code: Select all

OnRefreshAction=[!CommandMeasure MeasureDriveType "Run"]
Otherwise, you can add the !CommandMeasure bang to whatever measure suits your use-case.

To get info from different drives, just change the section of code that reads Get-Partition -DriveLetter 'C'. Replace the 'C' with the drive letter you are interested in. If you select a drive that does not exist, the measure will return a long error message.

Notice that this code can tell you things like whether the drive is an SD card, a RAID array, etc. You can add a series of IfMatch expressions to handle what to do with the different values.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: measure FreeDiskSpace option Type question

Post by Yincognito »

Yep, SilverAzide is most likely correct on this one. ^^ ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

Re: measure FreeDiskSpace option Type question

Post by nmdelrio »

SilverAzide wrote: April 16th, 2023, 10:59 pm Getting the InterfaceType for your drive probably isn't going to help you in this case, because -- based the issue in your original post -- it most likely will return the same thing as a fixed disk drive. (It does for me, anyway.) You need the BusType value.
...

Notice that this code can tell you things like whether the drive is an SD card, a RAID array, etc. You can add a series of IfMatch expressions to handle what to do with the different values.
Fantastic!

Thank you, thank you, thank you. That's exactly what I needed. Problem solved.

The reason I needed Rainmeter to detect if a disk is a USB drive is... I have 10 SATA ports (6 onboard, 4 add-in card). 9 of which permanently populated with SSD/HDD, and 1 is hot-pluggable (assigned N:). I use HWInfo plugin monitoring these drives (e.g., read/write activities, read/write rates, total read/write GB, S.M.A.R.T. info etc). Whenever a drive is plugged in the hot-pluggable port (i.e., N:), HWInfo re-assigns Device Instances. So I have a script in my skin that detects if there is a drive N: so the skin would re-assign proper Device Instances.

Code: Select all

[DriveNName]
Measure=FreeDiskSpace
Drive=N:
Label=1
UpdateDivider=5
Substitute="":"NOT CONNECTED"
IfMatch="NOT CONNECTED"

IfMatchAction=[!SetOption DriveNFreeBar ImageAlpha 0][!SetOption NTEMPMAX Text .][!SetOption NTEMP Text .][!SetOption NTempValue ImageAlpha 0][!SetOption DummyHistogramN PrimaryColor 0,0,0,0][!SetOption MeasureLowCapacityN Formula 0][!SetOption DriveNHistogram Hidden 1][!SetOption MeterLowCapacityN Text "NO DRIVE"][!HideMeter "NHeatGradient"]

IfNotMatchAction=[!SetOption DriveNFreeBar ImageAlpha 255][!SetVariable "IDSC" "0xa"][!SetVariable "IDSD" "0xb"][!SetVariable "IDSI" "0x6"][!SetVariable "IDSJ" "0x7"][!SetVariable "IDSK" "0x8"][!SetVariable "IDSL" "0x9"][!SetVariable "IDSN" "0x5"][!SetVariable "IDRWC" "0xa"][!SetVariable "IDRWD" "0xb"][!SetVariable "IDRWI" "0x6"][!SetVariable "IDRWJ" "0x7"][!SetVariable "IDRWK" "0x8"][!SetVariable "IDRWL" "0x9"][!SetVariable "IDRWN" "0x5"][!SetVariable "IDRWC" "0xa"][!SetVariable "IDRWD" "0xb"]
However, when a USB drive is connected and assigned N: by Windows, my skin re-assigns Device Instances thinking it is a fixed drive, but is instead a USB drive. HWInfo does not monitor USB drives thus does not assign a Device ID nor Device Instance, so the skin shows wrong read/writes, etc, for the wrong drives when tmy skin re-assigned Device Instances because thers is a drive N: present.

I can now use your RunCommand script to tell Rainmeter not to re-assign the HWInfo Device Instances though there is a drive N: if it is a USB drive.

Thank you both for the help. I truly appreciate it.

10-drives.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: measure FreeDiskSpace option Type question

Post by Yincognito »

nmdelrio wrote: April 17th, 2023, 12:01 amI use HWInfo plugin monitoring these drives (e.g., read/write activities, read/write rates, total read/write GB, S.M.A.R.T. info etc).
For the record, for most of those things, the UsageMonitor plugin included in the standard Rainmeter distribution represents another way to do it. It's only limited by the amount of Windows Performance Monitor counters.
nmdelrio wrote: April 17th, 2023, 12:01 amSo I have a script in my skin that detects if there is a drive N: so the skin would re-assign proper Device Instances.
Yeah, the only drawback when it comes to PowerShell solutions in these cases is that running PS every time is not exactly built for constant and frequent monitoring, it's much more ideal for one time initial or on demand queries - at least that's what I use it for. It's great to have it since its scripting is well developed compared to older batch / CMD ones, but it's also slower, unfortunately. The reality is that for some things, it is pretty much the only reliable option.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

Re: measure FreeDiskSpace option Type question

Post by nmdelrio »

Yincognito wrote: April 17th, 2023, 2:34 am For the record, for most of those things, the UsageMonitor plugin included in the standard Rainmeter distribution represents another way to do it. It's only limited by the amount of Windows Performance Monitor counters.
Yes, I read UsageMonitor plugin is a good alternative to HWInfo, unfortunately I am not savvy on performance Category and Counters, I just don't know where to find them. If there is a list or cheat sheet where I can find the counters I need, I am quite sure I can put them together. The good thing about HWInfo is that it presents the values in a silver platter, like being spoon fed and one just have to 'assemble' them together. Apart from the weather skin, all my system monitoring skins rely considerably, though not 100%, on HWInfo.
Yeah, the only drawback when it comes to PowerShell solutions in these cases is that running PS every time is not exactly built for constant and frequent monitoring, it's much more ideal for one time initial or on demand queries - at least that's what I use it for. It's great to have it since its scripting is well developed compared to older batch / CMD ones, but it's also slower, unfortunately. The reality is that for some things, it is pretty much the only reliable option.
Yes, I realised that PS is a bit slow. I tried using the above RunCommand for BusType to automatically activate an alternate config when a USB drive is plugged in, but realised that it is not practical for PS to be running at every update, like you mentioned
...not exactly built for constant and frequent monitoring...
Though I successfully got the skin to assign correct Device Instances when a USB drive is present. And since HWInfo does not monitor USB drives, I use UsageMonitor plugin for Bytes Read/sec. So far, I am happy with what I learned and managed to do in the past couple of days. :D
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: measure FreeDiskSpace option Type question

Post by Yincognito »

nmdelrio wrote: April 17th, 2023, 7:46 amYes, I read UsageMonitor plugin is a good alternative to HWInfo, unfortunately I am not savvy on performance Category and Counters, I just don't know where to find them.
PerfMon.jpg
The Rainmeter part is explained here.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth