It is currently April 27th, 2024, 8:00 am

FreeDiskSpace - network drive label problem

Get help with installing and using Rainmeter.
BSt86
Posts: 5
Joined: October 2nd, 2023, 11:28 am

FreeDiskSpace - network drive label problem

Post by BSt86 »

Hello everyone.
One thing in advance: Please excuse my bad English.

Following situation:
2 fixed partitions
- C: - Windows
- D: - Daten

6 network drives
- A: - Austausch
- M: - Management
- P: - Produktion
- T: - TimeLine
- V: - Verwaltung
- Z: - Home


I use a lot of FreeDiskSpace measures. Among other things, for reading the label. Unfortunately, I always get “Daten” back from network drives!

Am I too stupid to use all of this?

Here is an excerpt from my code:

Code: Select all

[Variables]
Drive2	= A:

;BLOCK Drive2
[measureDrive2Title]
Drive= #Drive2#
IgnoreRemovable= 0
Label= 1
Measure= FreeDiskSpace

[measureDrive2Total]
Drive= #Drive2#
DynamicVariables= 1
IgnoreRemovable= 0
Measure= FreeDiskSpace
Substitute= "K":"KB","M":"MB","G":"GB","T":"TB"
Total= 1
IfCondition= ((MeasureDrive2Total = 0) ||  ([shapeDrive2Click:Y] > (#FestplatteTop# + #FestplatteHeight# - 71)))
IfTrueAction= [!HideMeterGroup "Drive2"][!SetOption shapeDrive2Click Y  0R][!SetOption textDrive2Title Y 0r][!SetOption textDrive2Free Y  0r][!SetOption barDrive2Total Y  0r]
IfFalseAction= [!ShowMeterGroup "Drive2"][!SetOption shapeDrive2Click Y 15R][!SetOption textDrive2Title Y 2r][!SetOption textDrive2Free Y -4R][!SetOption barDrive2Total Y -4R]

[measureDrive2Used]
Drive= #Drive2#
IgnoreRemovable= 0
InvertMeasure= 1
Measure= FreeDiskSpace
Substitute= "K":"KB","M":"MB","G":"GB","T":"TB"

[measureDrive2UsedPercent]
Formula= (MeasureDrive2Total = 0) ? 1 : (MeasureDrive2Used / (MeasureDrive2Total + 0.000001))
Measure= Calc

[measureDrive2Free]
Drive= #Drive2#
InvertMeasure= 0
IgnoreRemovable= 0
Measure= FreeDiskSpace
Substitute= "K":"KB","M":"MB","G":"GB","T":"TB"

[shapeDrive2Click]
DynamicVariables=1
Group= Drive2
Meter= Shape
MyFillColor= Fill Color #BgColorNormal#
Shape= Rectangle 0,0,(#FestplatteWidth# - 10),([barDrive2Total:Y] - [shapeDrive2Click:Y] + [barDrive2Total:H] + 5) | Extend MyFillColor | StrokeWidth 0
X= (#FestplatteLeft# + 5)
Y= 15R
MouseOverAction= [!SetOption shapeDrive2Click MyFillColor "Fill Color #BgColorMO#"][!UpdateMeter shapeDrive2Click][!Redraw]
MouseLeaveAction= [!SetOption shapeDrive2Click MyFillColor "Fill Color #BgColorNormal#"][!UpdateMeter shapeDrive2Click][!Redraw]
LeftMouseDownAction= !Execute ["explorer" "#Drive2#"]

[textDrive2Title]
Group= Drive2
Meter= String
MeterStyle= styleTextTitle
NumOfDecimals= 1
StringAlign= Left
Text= "(#Drive2#)"
X= 5r
Y= 2r

[textDrive2Title2]
DynamicVariables=1
Group= Drive2
MeasureName= MeasureDrive2Title
Meter= String
MeterStyle= styleTextTitle
StringAlign= Left
Text= "%1"
X= 65r
Y= 0r

[textDrive2Free]
AutoScale= 1
DynamicVariables= 1
Group= Drive2
MeasureName= MeasureDrive2Free
Meter= String
MeterStyle= styleTextText
NumOfDecimals= 1
StringAlign= Left
Text= "%1"
X= ([textDrive2Title:X])
Y= -4R

[textDrive2FreiVon]
AutoScale= 1
DynamicVariables= 1
Group= Drive2
Meter= String
MeterStyle= styleTextSubText
NumOfDecimals= 1
StringAlign= CenterCenter
Text= "frei von"
X= (#FestplatteLeft# + (#FestplatteWidth# / 2))
Y= ([textDrive2Free:H] / 2)r

[textDrive2Total]
AutoScale=1
DynamicVariables=1
Group= Drive2
MeasureName= MeasureDrive2Total
Meter= String
MeterStyle= styleTextText
NumOfDecimals= 1
StringAlign= Right
Text= "%1"
X= (#FestplatteLeft# + #FestplatteWidth# - 10)
Y= ([textDrive2Free:Y])



[barDrive2Total]
DynamicVariables=1
Group= Drive2
Meter= Shape
Shape= Rectangle 0,0,(#FestplatteWidth# - 20),10 | Fill Color #BarColorTotal#
UpdateDivider= 1
X= ([textDrive2Title:X])
Y= -4R

[barDrive2Used]
DynamicVariables= 1
Group= Drive2
Meter= Shape
Shape= Rectangle 0,0,((#FestplatteWidth# - 20) * [measureDrive2UsedPercent]),10 | Fill Color #FontColorTitle#
X= 0r
Y= 0r
;BLOCKEND Drive2

Can anybody help me with this please?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: FreeDiskSpace - network drive label problem

Post by SilverAzide »

BSt86 wrote: October 2nd, 2023, 11:37 am I use a lot of FreeDiskSpace measures. Among other things, for reading the label. Unfortunately, I always get “Daten” back from network drives!
What are the drive labels on the network drives you are mapped to? I am asking because the FreeDiskSpace measure returns the drive labels, not the network file share names.
Gadgets Wiki GitHub More Gadgets...
BSt86
Posts: 5
Joined: October 2nd, 2023, 11:28 am

Re: FreeDiskSpace - network drive label problem

Post by BSt86 »

Hey SilverAzide, Sorry for didn't make myself clear

2 fixed partitions
- C: >>> "Windows"
- D: >>> "Daten"

6 network drives
- A: >>> "Austausch"
- M: >>> "Management"
- P: >>> "Produktion"
- T: >>> "TimeLine"
- V: >>> "Verwaltung"
- Z: >>> "Home"


when I want to get the label for "C:" I get "Windows", that's correct.
But when I want to get the label for "A:" I get "Daten" even though it should be "Austausch"!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: FreeDiskSpace - network drive label problem

Post by SilverAzide »

BSt86 wrote: October 2nd, 2023, 12:26 pm
Got it... if you open a command window and do a DIR command for that drive, what do you get?

Code: Select all

C:\>net use q: \\myserver\myshare
The command completed successfully.

C:\>dir q:
 Volume in drive Q is MY_LABEL
 Volume Serial Number is C643-4318

 Directory of Q:\
etc.
The measure for Q: would return "MY_LABEL". Is this not what you are seeing?
Gadgets Wiki GitHub More Gadgets...
BSt86
Posts: 5
Joined: October 2nd, 2023, 11:28 am

Re: FreeDiskSpace - network drive label problem

Post by BSt86 »

Here I don't get the correct return value, too.

I map the drive with "net use q: \\FS1\FS"

Then I get the following back with “dir q:”:
"Volume in drive Q is Daten"
....


I switched remotely to the server on which the network devices were originally located. Here the drive on which the folders are located is also called “Daten”. I think that's why the measure returns this value to me. But I thought it would give me the name I gave the drive in Explorer!
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: FreeDiskSpace - network drive label problem

Post by Yincognito »

BSt86 wrote: October 2nd, 2023, 1:26 pm But I thought it would give me the name I gave the drive in Explorer!
I'm not a network specialist, but could it be because the Explorer names are just some sort of aliases? :???: Maybe you could try getting those values (if they are indeed something Explorer specific) another way? Like investigating
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 using a Registry measure in Rainmeter? This is untested, obviously, but might lead you closer to what you want.. :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: FreeDiskSpace - network drive label problem

Post by SilverAzide »

BSt86 wrote: October 2nd, 2023, 1:26 pm Here I don't get the correct return value, too.

I map the drive with "net use q: \\FS1\FS"

Then I get the following back with “dir q:”:
"Volume in drive Q is Daten"
....


I switched remotely to the server on which the network devices were originally located. Here the drive on which the folders are located is also called “Daten”. I think that's why the measure returns this value to me. But I thought it would give me the name I gave the drive in Explorer!
So it is working correctly then. I think you are confusing drive labels with drive names. If you assign a name to a network drive, you'll need to use a different approach to retrieve this value. (I'm not sure where Windows stores this info, sometimes it's in a hidden .ini/.inf file, sometimes the registry).
Gadgets Wiki GitHub More Gadgets...
BSt86
Posts: 5
Joined: October 2nd, 2023, 11:28 am

Re: FreeDiskSpace - network drive label problem

Post by BSt86 »

@Yincognito
I think the registry is the right direction.
But now I'm faced with the next problem.
This gives me a list of subkeys:

Code: Select all

[measureReg]
Measure			= Registry
RegHKey			= HKEY_CURRENT_USER
RegKey			= Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
OutputType=SubkeyList
But how can I read out the individual subkeys? It should work like this:

Code: Select all

[measureSubkey]
Measure			= Registry
RegHKey			= HKEY_CURRENT_USER
RegKey			= Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\???? <==== How to fill it with the result from [measureReg]
RegValue		= _LabelFromReg
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: FreeDiskSpace - network drive label problem

Post by Yincognito »

BSt86 wrote: October 4th, 2023, 10:38 am @Yincognito
I think the registry is the right direction.
But now I'm faced with the next problem.
This gives me a list of subkeys:

Code: Select all

[measureReg]
Measure			= Registry
RegHKey			= HKEY_CURRENT_USER
RegKey			= Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
OutputType=SubkeyList
But how can I read out the individual subkeys? It should work like this:

Code: Select all

[measureSubkey]
Measure			= Registry
RegHKey			= HKEY_CURRENT_USER
RegKey			= Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\???? <==== How to fill it with the result from [measureReg]
RegValue		= _LabelFromReg
Well, with a bit of regex and string manipulation, you can extract any (or all, if you replicate the last 2 measures in a sufficient manner and using hardcoded index values) individual subkeys, using something like (scrolling is for better illustrating it):

Code: Select all

[Variables]
RegKeyRoot=Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
SubKeyIndex=0

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,255,0,255

---Measures---

[measureReg]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=#RegKeyRoot#
OutputType=SubkeyList

[measureSubKeyCountSum]
Measure=String
String=[measureReg]#CRLF#
RegExpSubstitute=1
Substitute="\N":"","\R":"+1"
DynamicVariables=1

[measureSubKeyCount]
Measure=Calc
Formula=[measureSubKeyCountSum]
DynamicVariables=1

[measureSubKeyName]
Measure=String
String=[measureReg]#CRLF#
RegExpSubstitute=1
Substitute="(?siU)^(?:(?:.*\R){0,#SubKeyIndex#}+(.*)\R.*?|.*?)$":"\1","^\\1$":""
DynamicVariables=1

[measureSubKey]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=#RegKeyRoot#\[measureSubKeyName]
RegValue=_LabelFromReg
DynamicVariables=1

---Meters---

[Result]
Meter=String
AntiAlias=1
MeasureName=measureSubKeyName
MeasureName2=measureSubKey
Text=RegKey (Root) = #RegKeyRoot##CRLF#SubKey (Name) = %1#CRLF#SubKey (Value) = %2
UpdateDivider=-1
MouseScrollUpAction=[!SetVariable SubKeyIndex (Clamp(#SubKeyIndex#-1,0,[measureSubKeyCount]-1))][!UpdateMeasure *][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable SubKeyIndex (Clamp(#SubKeyIndex#+1,0,[measureSubKeyCount]-1))][!UpdateMeasure *][!UpdateMeter *][!Redraw]
DynamicVariables=1
Registry MountPoints.jpg
In the 2nd measure:
- take the string value of the 1st measure and add a list separator (newline, in this case) to it for consistency
- remove the \N aka not newlines
- convert the \R aka newlines to +1 to compute the subkeys count

In the 3rd measure:
- use the string value of the 2nd measure as the formula to count the number of subkeys

In the 4th measure:
- (?:skip) as many subkeys aka .*\R as possible up to #SubKeyIndex# using {quantifiers}, (capture) the following subkey and discard the rest aka .*?
- remove the empty captures that Rainmeter doesn't like and turns to the literal \1 and so on, to keep things clean

In the 5th measure:
- simply use the value of the 4th measure in the RegKey path, to get that specific subkey

In the scroll actions:
- optionally, clamp / limit the scrolled value between 0 (the 1st index) to the index count minus 1

Alternatives to the above:
- a Lua script to do this in a "real" scripting language
- a PowerShell command / script to do the same from a RunCommand measure, maybe even using some "built-in" data instead of fishing in the registry
- a hypothetical command line that can get what you want

References: https://regexr.com/ after setting the flavor to PCRE from the top right buttons and clicking RegEx Reference in the left sidebar
P.S. Sorry for the delay in responding.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
BSt86
Posts: 5
Joined: October 2nd, 2023, 11:28 am

Re: FreeDiskSpace - network drive label problem

Post by BSt86 »

@Yincognito
I tried using Powershell's approach and actually managed to solve it. I just have to play around with the UpdateDivider to improve performance.

My solution now looks something like this:

Code: Select all

[Rainmeter]
Update		= 1000
OnRefreshAction	= [!CommandMeasure measureGetNetDrives "Run"

[Variables]
Drive01	= C:
Drive02	= D:
Drive03	= A:
Drive04	= B:
Drive05	= E:
Drive06	= F:
...

[measureGetNetDrives]
Measure		= Plugin
Plugin		= RunCommand
Program		= PowerShell
Parameter	= $SubKeys = Get-ChildItem -Path Registry::HKCU\Network | Where-Object {($_.Property -eq 'RemotePath')}; foreach($SubKey in $SubKeys) { $SubKey.Name.SubString($SubKey.Name.Length - 1, 1).ToUpper() + ':--' + (Get-ItemProperty -Path Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\$((Get-ItemProperty -Path Registry::$($SubKey.Name)).RemotePath.Replace('\','#')))._LabelFromReg + '---'; };
State		= Hide
OutputType	= ANSI
OutputFile	= #CURRENTPATH#_DATA_NetDrives.txt
RegExpSubstitute= 1


[measureDrive01Type]
Drive		= #Drive01#
IgnoreRemovable	= 0
Measure		= FreeDiskSpace
Type		= 1
IfCondition	= (measureDrive01Type = 3)
IfTrueAction	= [!SetOption imageDrive01Type ImageName "#@#\Images\drive_removable.png"][!UpdateMeter imageDrive01Type][!SetOption textDrive01Title2 MeasureName "MeasureDrive01Title"][!Redraw]
IfCondition2	= (measureDrive01Type = 4)
IfTrueAction2	= [!SetOption imageDrive01Type ImageName "#@#\Images\drive_fixed.png"][!UpdateMeter imageDrive01Type][!SetOption textDrive01Title2 MeasureName "MeasureDrive01Title"][!Redraw]
IfCondition3	= (measureDrive01Type = 5)
IfTrueAction3	= [!SetOption imageDrive01Type ImageName "#@#\Images\drive_network.png"][!UpdateMeter imageDrive01Type][!EnableMeasure measureDrive01NetName][!SetOption textDrive01Title2 MeasureName "measureDrive01NetName"][!UpdateMeter textDrive01Title2][!Redraw]

[measureDrive01NetName]
Disabled	= 1
FinishAction	= !DisableMeasure measureDrive01NetName
Measure		= Plugin
Plugin		= Webparser
Url		= file://#CURRENTPATH#_DATA_NetDrives.txt
RegExp		= (?siU)#Drive01#--(.*)---
StringIndex	= 1

[measureDrive01Title]
Drive	= #Drive01#
Measure	= FreeDiskSpace
Label	= 1

	[textDrive01Title2]
	DynamicVariables= 1
	Group			= Drive2
	MeasureName		= MeasureDrive01Title
	Meter			= String
	MeterStyle		= styleTextTitle
	StringAlign		= Left
	Text			= "%1"
	X			= 10R
	Y			= 0r


Thank you all for your help!