Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find if any storage or pen drive is connected at the movement.

Hi,

I need to find if any storage or webcam or any device is connected to the USB excluding keyboard and mouse.Script to scan all machines in the file to do this.

Regards
Sharath
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

There is an excellent utility 'USBDeview'.
USBDeview is a small utility that lists all USB devices that currently connected to your computer, as well as all USB devices that you previously used.

Download it from:
http://www.nirsoft.net/utils/usb_devices_view.html

To view USB devices on remote system following these steps
Download and exctract usbdeview.zip on C: drive
Start -> Run -> C:\usbdeview\USBDeview.exe /remote \\SERVER
                                                                                           ^---- Remote system name
                                                                           


Avatar of bsharath

ASKER

Any way you can put this to a script to scan all machines in a file.
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But this shows any thing that is connected.How can i find what is connected at the moment
If you can look into the 'Connected' column it will show you 'YES' for the devices that are currently connected to the system.
You can also click on the 'Connected' column header to sort the list.
Avatar of Gastone Canali
'
' get-usb-devicetype-all-PCs.vbs
' read the computer computers list from the file c:\computers.txt
' for get output on file run:
' Gastone Canali
'
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
do while not objFile.AtEndOfStream
    PC = objFile.ReadLine
    getUSBinfo (PC)
loop
objFile.Close
'http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar05/hey0315.mspx
sub getUSBinfo(strComputer)
  On Error Resume Next
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   Set colDevices = objWMIService.ExecQuery _
    ("Select * From Win32_USBControllerDevice")
    If Err.Number = 0 then
    For Each objDevice in colDevices
        strDeviceName = objDevice.Dependent
        strQuotes = Chr(34)
        strDeviceName = Replace(strDeviceName, strQuotes, "")
        arrDeviceNames = Split(strDeviceName, "=")
        strDeviceName = arrDeviceNames(1)
        Set colUSBDevices = objWMIService.ExecQuery _
           ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
        For Each objUSBDevice in colUSBDevices
           Wscript.Echo strComputer&": "& objUSBDevice.Description
        Next    
  Next
  else
     Wscript.Echo strComputer&": Error computer not found"
    err.clear
  end if
 
end sub
Canali.

I get such boxes.

---------------------------
Windows Script Host
---------------------------
dev-chen-mrd100: USB Root Hub
---------------------------
OK  
---------------------------

For every machine i get 4 to 6 times...
at the command prompt run the following command
cscript //H:CScript
and then run  
get-usb-devicetype-all-PCs.vbs >usb.txt
you get the list af all usb device...
I get this.


C:\>cscript //H:CScript
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

The default script host is now set to "cscript.exe".

C:\>get-usb-devicetype-all-PCs.vbs usb.txt
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

dev-chen-mrd100: USB Root Hub
dev-chen-mrd100: USB Root Hub
dev-chen-mrd100: USB Root Hub
dev-chen-mrd100: USB Root Hub
dev-chen-mrd100: USB Root Hub
indiasophos: USB Root Hub
indiasophos: USB Root Hub
indiasophos: USB Root Hub
indiasophos: USB Composite Device
indiasophos: USB Human Interface Device
indiasophos: HID Keyboard Device
indiasophos: USB Human Interface Device
indiasophos: HID-compliant mouse
indiasophos: HID-compliant consumer control device
indiasophos: HID-compliant device
indiasophos: USB Root Hub
indiasophos: Generic USB Hub
hydsophos: USB Root Hub
hydsophos: USB Composite Device
hydsophos: USB Human Interface Device
hydsophos: HID Keyboard Device
hydsophos: USB Human Interface Device
hydsophos: HID-compliant mouse
hydsophos: USB Root Hub
hydsophos: USB Root Hub
hydsophos: USB Composite Device
hydsophos: USB Human Interface Device
hydsophos: HID Keyboard Device
hydsophos: USB Human Interface Device
hydsophos: HID-compliant mouse
hydsophos: HID-compliant consumer control device
hydsophos: HID-compliant device
hydsophos: USB Root Hub
hydsophos: Generic USB Hub
: Error computer not found
: Error computer not found
: Error computer not found

C:\>
If you want output in a file run this command:
cscript //nologo get-usb-devicetype-all-PCs.vbs        >      usb.txt

if you want a exclude keyb mouse.... run this single line command assuming get-usb-devicetype-all-PCs.vbs inc :\
cscript //nologo c:\get-usb-devicetype-all-PCs.vbs |find /i /v "USB Root "|find /i /v "USB Hub"|find /i /v "HID Keyboard Device"|find /i /v "mouse"
Canali.

I get this.


C:\>cscript //nologo c:\get-usb-devicetype-all-PCs.vbs |find /i /v "USB Root "|f
ind /i /v "USB Hub"|find /i /v "HID Keyboard Device"|find /i /v "mouse"
indiasophos: USB Composite Device
indiasophos: USB Human Interface Device
indiasophos: USB Human Interface Device
indiasophos: HID-compliant consumer control device
indiasophos: HID-compliant device
hydsophos: USB Composite Device
hydsophos: USB Human Interface Device
hydsophos: USB Human Interface Device
hydsophos: USB Composite Device
hydsophos: USB Human Interface Device
hydsophos: USB Human Interface Device
hydsophos: HID-compliant consumer control device
hydsophos: HID-compliant device
: Error computer not found
: Error computer not found
: Error computer not found
Can you exclude all these thing in the script so that shall only get storage,Wecams,Pen drives etc.

When i scan 100's of machines it becomes too difficult to search...
Sharath whats wrong with following? It does not give you the result that you want? like currently connected devices?
C:\usbdeview\USBDeview.exe /remotefile "C:\Computers.txt"
Farhan.

This option is great...

I just though as Canali has also answer this Q wanted to see if i am doing something wrong from my end...

Ok Canali thanks for all the help.I shall close this Q here...