It is currently April 18th, 2024, 11:51 pm

Detecting a USB device (specifically, a webcam)

Get help with creating, editing & fixing problems with skins
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Detecting a USB device (specifically, a webcam)

Post by jn_meter »

Hello! :welcome:

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.
User avatar
CyberTheWorm
Posts: 860
Joined: August 22nd, 2016, 11:32 pm
Location: Surrey, B.C., Canada

Re: Detecting a USB device (specifically, a webcam)

Post by CyberTheWorm »

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
User avatar
Bananorpion
Posts: 40
Joined: April 16th, 2017, 8:35 pm

Re: Detecting a USB device (specifically, a webcam)

Post by Bananorpion »

My guess would be using the RunCommand measure type. Which Windows programs/commands do you use to get your information?
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

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.
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

Bananorpion wrote:My guess would be using the RunCommand measure type.
That would make sense . .
Bananorpion wrote:Which Windows programs/commands do you use to get your information?
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.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Detecting a USB device (specifically, a webcam)

Post by jsmorley »

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.
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

Wowser: a useful page and useful command. That might be able to do it. I'll investigate. Thank you.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Detecting a USB device (specifically, a webcam)

Post by jsmorley »

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
User avatar
Bananorpion
Posts: 40
Joined: April 16th, 2017, 8:35 pm

Re: Detecting a USB device (specifically, a webcam)

Post by Bananorpion »

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"
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Detecting a USB device (specifically, a webcam)

Post by jsmorley »

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.