Hello!
I've a fairly complex Rainmeter skin that does lots of things, and my level of Rainmeter knowledge is decent enough. However, I don't know how to detect whether or not a particular USB device - a webcam - is plugged in or not. I can get various details about this device via various Windows and third-party programs; what I don't know is how to make use of that information to detect, via Rainmeter and fairly efficiently (I'll use a timer that runs every 15 seconds or so), whether the device is plugged in.
Can anyone think of a way to do this, please? Thanks.
It is currently April 18th, 2024, 11:51 pm
Detecting a USB device (specifically, a webcam)
-
- Posts: 136
- Joined: December 27th, 2016, 12:04 pm
-
- Posts: 860
- Joined: August 22nd, 2016, 11:32 pm
- Location: Surrey, B.C., Canada
Re: Detecting a USB device (specifically, a webcam)
I did write this to detect if my F: USB drive got plugged in, maybe that could be a start? It automatically loads another skin. Not sure if you can do it for webcam though. You might be able to modify the first part to detect that devices if you can get the skin to read it's active.
Code: Select all
[MeasureDriveFExists]
Measure=FreeDiskSpace
IgnoreRemovable=0
Drive=F:
Type=1
IfAboveValue=1
IfAboveAction=[!ActivateConfig "SmallSkin\Drives\F" "Drive.ini"]
IfBelowValue=2
IfBelowAction=[!DeactivateConfig "SmallSkin\Drives\F"]
The only source of knowledge is experience. Albert Einstein
Deviant Art Page
Deviant Art Page
-
- Posts: 40
- Joined: April 16th, 2017, 8:35 pm
Re: Detecting a USB device (specifically, a webcam)
My guess would be using the RunCommand measure type. Which Windows programs/commands do you use to get your information?
-
- Posts: 136
- Joined: December 27th, 2016, 12:04 pm
Re: Detecting a USB device (specifically, a webcam)
Thanks for the response. The thing is, though, that the webcam has no drive letter - because it is not a drive.
Perhaps the 'perfmon' plug can be used to do the job.
Perhaps the 'perfmon' plug can be used to do the job.
-
- Posts: 136
- Joined: December 27th, 2016, 12:04 pm
Re: Detecting a USB device (specifically, a webcam)
That would make sense . .Bananorpion wrote:My guess would be using the RunCommand measure type.
Yet, I am getting the information from graphical programs - namely, the Windows Device Manager, and the third-party program 'USB safely remove'. So I don't know what commands to run from Rainmeter.Bananorpion wrote:Which Windows programs/commands do you use to get your information?
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Detecting a USB device (specifically, a webcam)
I would be tempted to explore using RunCommand to execute a WMIC command to look for the device and get its "status".
http://programming.realworldrobotics.com/editors-ides/command-line-in-windows/wmic-snippets
I suspect you will need some hardware identification details to pass to WMIC, but sounds like maybe you can get that information for your device from device manager.
http://programming.realworldrobotics.com/editors-ides/command-line-in-windows/wmic-snippets
I suspect you will need some hardware identification details to pass to WMIC, but sounds like maybe you can get that information for your device from device manager.
-
- Posts: 136
- Joined: December 27th, 2016, 12:04 pm
Re: Detecting a USB device (specifically, a webcam)
Wowser: a useful page and useful command. That might be able to do it. I'll investigate. Thank you.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Detecting a USB device (specifically, a webcam)
As a starting point, I think you can list all currently connected USB devices with:
wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value
wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value
-
- Posts: 40
- Joined: April 16th, 2017, 8:35 pm
Re: Detecting a USB device (specifically, a webcam)
May be relevant to your interests: An example skin using a WMIC command
Code: Select all
[MeasureMaxCPUSpeed]
Measure=PLUGIN
Plugin=RunCommand
Program=wmic
Parameter=cpu get MaxClockSpeed
OutputType=ANSI
RegExpSubstitute=1
Substitute="MaxClockSpeed\s+#CRLF#(\d+)\s+":"\1"
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Detecting a USB device (specifically, a webcam)
Just a word of caution, never use WMIC to "poll" for information constantly. WMIC is slow as molasses in January, and will use more CPU than you will like. It's ok a few times a minute or so, but never, ever once a second.