Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I keep leaving my usb drives connected to the lab machines of my dept.So far I have been lucky to always find it in the lost and found but not having it when you need it gets a bit irritating.

Is there a utility/script available that will prompt me to remove it before I log off ?
I am looking for solution for doing this both in Windows and Linux.
Any pointers on how to go about writing one ?

share|improve this question
    
occupancy sensor + programming language automation - MatLab, Labview, C, C++,JAVA –  STTR Feb 11 '13 at 20:24
    
I suggest posting separate questions for each OS, otherwise it becomes difficult to accept answers unless someone is able to satisfy all your OS requirements. –  Karan Feb 14 '13 at 17:18

1 Answer 1

A simple VBScript to check for presence of removable devices would look like this:

boolDeviceFound = False
strComputer = InputBox("Enter the name of the computer to search for USB devices:")
strComputer = Trim(strComputer)
If LenB(strComputer) = 0 Then
    strComputer = "."
End If

'Query the WMI service for the computer name
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Display the connected computer
WScript.Echo "You have successfully connected to computer " & strComputer

Set colItems = objWMIService.ExecQuery("SELECT * from Win32_LogicalDisk WHERE Description = 'Removable Disk'")
For Each objItem in colItems
    WScript.Echo "The computer " & strComputer & " has a removable USB drive connected with drive letter: " & objItem.Name
    WScript.Echo "Please remove this device from " & strComputer & " to comply with Lab policies!"
    boolDeviceFound = True
Next

If boolDeviceFound = False Then
    WScript.Echo "No USB devices found!"
End If

If you save it as something like DetectUSB.vbs, it can be executed from the command line or a batch file using wscript DetectUSB.vbs. Something similar can be written using PowerShell as well, and the batch file/PS script can be set as a logoff script. Only problem is, do you even have sufficient rights on the lab PC(s) to install logoff scripts?

share|improve this answer
    
If the scripts do work, the lab admin might install it on the machines since a lot of people seem to be leaving their usbs on the machines –  Shekhar Feb 20 '13 at 21:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.