Jump to content

List all connected Webcams


Recommended Posts

Hey guys, I've searched around for on the forums but I haven't found it. Is there a way to look into all of the drivers and list all of the webcams there in a combo box or something... maybe someone has written a UDF for it or something. Anyway I need it for this project i'm working on. Any help is appreciated.

Thanks

Apples292

Link to comment
Share on other sites

  • Moderators

Hi, Apples292. I don't have a webcam connected to test, but the code below should get you started. It queries WMI on the machine for a list of USB-connected devices. Once you find something that is unique to your cameras (the word camera in the name, for example), you can narrow the search and then feed the results into your GUI.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"

$WMI = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
Local $aItems = $WMI.ExecQuery("SELECT * FROM Win32_USBDevice", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($aItems) then
   For $element In $aItems
    MsgBox(0, "======" & $element.Name & "======", "Manufacturer: " & $element.Manufacturer & @CRLF & @CRLF & "Description: " & $element.Description)
   Next
Else
   Msgbox(0,"","No WMI Objects Found for class: " & "Win32_USBDevice" )
Endif

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thx for replying JLogan, I tried your code with and without a webcam (I also tried a memory stick) attached however I didn't get a MsgBox at all...

Am I missing something here, maybe I have to change this?

$strComputer = "localhost"

Thanks

Apples292

Link to comment
Share on other sites

  • Moderators

Localhost is just the local computer. You can change it to use the @ComputerName macro, but it should not make a difference.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Nope... as u said it didn't make any difference. Maybe it's just that the webcam + USB stick isn't compatible I really have no idea...

Thanks

Apples292

P.S Do u have any idea why it doesn't send the

Msgbox(0,"","No WMI Objects Found for class: " & "Win32_USBDevice" )

because it should...

Edited by Apples292
Link to comment
Share on other sites

  • Moderators

It should define everything in USB in WMI. Try adding this line:

MsgBox(0, "", "Yes, I am an object!")

right after the If IsObj line, and let me know what you see.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I did that, I now get the

MsgBox(0, "", "Yes, I am an object!")

everytime I run it, whether there is a webcam/USB stick in or not

Thanks

Apples292

BTW: This is what I've been trying

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"

$WMI = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
Local $aItems = $WMI.ExecQuery("SELECT * FROM Win32_USBDevice", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($aItems) then
MsgBox(0, "", "Yes, I am an object!")
For $element In $aItems
MsgBox(0, "======" & $element.Name & "======", "Manufacturer: " & $element.Manufacturer & @CRLF & @CRLF & "Description: " & $element.Description)
Next
Else
Msgbox(0,"","No WMI Objects Found for class: " & "Win32_USBDevice" )
Endif
Edited by Apples292
Link to comment
Share on other sites

  • Moderators

So, the MsgBox shows that it is obtaining the object correctly. You should be able to remove that line now, as it proved that you're good up to that point. The code looks right - can you tell me what Operating System and AutoIt Version you're running this in?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

What are you running this on? Windows XP Pro v 2002 is coming up listed as a 64 bit Itanium version of XP. Is that what you're running for an OS?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

I know Wikipedia shows Pro v 2002 as being Itanium, but I know it is not limited to that alone. For example, all of my VMs (both VMWare and VirtualBox) show up as this version.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Which is why I need the OP to tell me what it's running on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

When I run scriptomatic on 2 versions of Windows (Win7 x64, and XP x86) it doesn't show Win32_USBDevice on either machine. I'm not sure why that is, but it might not be available on all systems.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...