It is currently April 16th, 2024, 7:31 pm

Matching a drive name to a string.

Get help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Matching a drive name to a string.

Post by kyriakos876 »

Hello, I had an idea that's goes like this:
Say I have a USB connected to my PC and on the windows explorer it's identified as G: SanDisk

I want to have a measure that checks the name of the drive G and match it with a set string. So if I have a variable access=SanDisk and then a measure like

Code: Select all

[MeasureString]
Measure=Plugin
Plugin=Sysinfo
(Insert code that gets the name of the drive G here)
OnupdateAction=[!SetVariable connected [MeasureString] ]

[MeasureCheck]
Measure=String
String=#connected#
IfMatch=#access#
IfMatchAction=[!DoSomething]
IfNotMatchAction=[!DoSomethingElse]
Now this obviously doesn't work for the main reason being that I don't know the syntax to get the name of the connected USB. How could I do that, if possible?

-Thabks in advance and I hope I'm being understandable.
Last edited by kyriakos876 on April 16th, 2018, 1:05 am, edited 1 time in total.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Matching a drive name to a string.

Post by FreeRaider »

I think you can not use sysinfo plugin to get that kind of information.


I know this command, which you could use with runcommand plugin

wmic logicaldisk where drivetype=2 get name, volumename

Using in wmic console I get:

Code: Select all

Name    VolumeName
G:      SANDISK
I hope this helps you.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Matching a drive name to a string.

Post by kyriakos876 »

FreeRaider wrote:I think you can not use sysinfo plugin to get that kind of information.


I know this command, which you could use with runcommand plugin

wmic logicaldisk where drivetype=2 get name, volumename

Using in wmic console I get:

Code: Select all

Name    VolumeName
G:      SANDISK
I hope this helps you.
I used SysInfo as an example to show what I want to do. I'll try what you suggested and tell you how it went!
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Matching a drive name to a string.

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]

[MeasureDiskLabel]
Measure=FreeDiskSpace
Drive=G:
Label=1
IfMatch=(?i)^sandisk$
IfMatchAction=[!SetOption MeterOne Text "Drive G: named SANDISK"][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterOne Text "Drive G: NOT named SANDISK"][!UpdateMeter *][!Redraw]

[MeterDriveName]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Matching a drive name to a string.

Post by kyriakos876 »

jsmorley wrote:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]

[MeasureDiskLabel]
Measure=FreeDiskSpace
Drive=G:
Label=1
IfMatch=(?i)^sandisk$
IfMatchAction=[!SetOption MeterOne Text "Drive G: named SANDISK"][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterOne Text "Drive G: NOT named SANDISK"][!UpdateMeter *][!Redraw]

[MeterDriveName]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
I come here to post how this worked:

Code: Select all

[Rainmeter]
Update=1000
OnUpdateAction=[!CommandMeasure MeasureRun "Run"]

[Variables]
Key=SANDISK

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk where drivetype=2 get name, volumename
OutputType=ANSI
RegExpSubstitute=1
Substitute="Name.*#CRLF#":"","#CRLF#":""
IfMatch=#key#    
IfMatchAction=[!DeactivateConfig "Statistics\Locked" "Locked.ini"]
IfNotMatchAction=[!ActivateConfig "Statistics\Locked" "Locked.ini"]

[MeterRun]
Meter=String
and I see your solution. It just happens that FreeRaider's solution better fits my case as it works with any drive letter... so if I have my usb at the E: port for example, it will still work. (I didn't mention I wanted that because I didn't know I did until I needed it that ^_^ ) as this is going to be used like a "Lock USB" that when remove locks the PC and when inserted unlocks it, you can't always know it's going to be in the G letter.