Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if any USB devices connected on Logout?? 1

Status
Not open for further replies.

Sharpharp

IS-IT--Management
Jun 9, 2009
29
GB
Hi all,

I've been tasked to find out if there is a way of warning users that they have left a USB device or memory card left inserted in a USB card reader, when the USER logs out.

We have a lot of users to leave usb memory sticks plugged in or cards in the usb card readers. This is in a public PC area, so I was wondering if its possible to build a VBScript that runs on Logout that can detect if any USB Memory Sticks or Cards are left inserted on a PC.

Any help would be appreciated, i've googled a few articles, but couldn't find anything on the subject.

Thanks in advance
Sharpy
 
I really don't liek the idea of overly delaying logout, but you can put a pause in that waits for user input like this:

Code:
On Error Resume Next
dim oWMP, colCDROMs, i, strComputer, objWMIService, colItems, objItem

Const CDROM = 4
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
    If objItem.MediaLoaded <> 0 Then
    'Use the below line instead of above to eject if empty
    'If objItem.MediaLoaded = 0 Then
        Eject objItem.Drive 
    End If
Next

Sub Eject(Drive)
 Set oWMP = Wscript.CreateObject("WMPlayer.OCX.7")
 Set colCDROMs = oWMP.cdromCollection

 if colCDROMs.Count >= 1 then

 For i = 0 to colCDROMs.Count - 1
     If oWMP.cdromCollection.item(index).driveSpecifier = Drive Then
        colCDROMs.Item(i).Eject 
 		MsgBox "Please remove the CD/DVD from the drive and click OK to continue shutdown."
 		colCDROMs.Item(i).Eject
     End If
 Next

 End If
 
  
 oWMP.close
 set colCDROMs = nothing
 set oWMP = nothing
 set i = nothing
End Sub

An alternative, with just a delay (and having the sleep in the right place -sorry)

Code:
On Error Resume Next
dim oWMP, colCDROMs, i, strComputer, objWMIService, colItems, objItem

Const CDROM = 4
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
    If objItem.MediaLoaded <> 0 Then
    'Use the below line instead of above to eject if empty
    'If objItem.MediaLoaded = 0 Then
        Eject objItem.Drive 
    End If
Next

Sub Eject(Drive)
 Set oWMP = Wscript.CreateObject("WMPlayer.OCX.7")
 Set colCDROMs = oWMP.cdromCollection

 if colCDROMs.Count >= 1 then

 For i = 0 to colCDROMs.Count - 1
     If oWMP.cdromCollection.item(index).driveSpecifier = Drive Then
        colCDROMs.Item(i).eject : WScript.Sleep 5000 : colCDROMs.Item(i).Eject
     End If
 Next

 End If
 
  
 oWMP.close
 set colCDROMs = nothing
 set oWMP = nothing
 set i = nothing
End Sub

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark, why not using the WshShell.Popup method to have the message AND the sleep ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
An excellent suggestion PHV. I so seldomly use WSHShell.Popup that I forget about it.

Code:
On Error Resume Next
dim oWMP, colCDROMs, i, strComputer, objWMIService, colItems, objItem
Const CDROM = 4
strComputer = "."


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
    If objItem.MediaLoaded <> 0 Then
    'Use the below line instead of above to eject if empty
    'If objItem.MediaLoaded = 0 Then
        Eject objItem.Drive 
    End If
Next

Sub Eject(Drive)
 Set WshShell = CreateObject("WScript.Shell")
 Set oWMP = Wscript.CreateObject("WMPlayer.OCX.7")
 Set colCDROMs = oWMP.cdromCollection

 if colCDROMs.Count >= 1 then

 For i = 0 to colCDROMs.Count - 1
     If oWMP.cdromCollection.item(index).driveSpecifier = Drive Then
        colCDROMs.Item(i).Eject 
         WshSHell.Popup "Please remove the CD/DVD from the drive and click OK to continue shutdown.",5,"Remove CD",48
         colCDROMs.Item(i).Eject
     End If
 Next

 End If
 
  
 oWMP.close
 set colCDROMs = nothing
 set oWMP = nothing
 set i = nothing
End Sub

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Great idea, i like the pop up box, and the drive tray stayed out slightly longer.

Ok, one final final final query :) This is just for added entertainment value.

I have added a script which uses the system motherboard internal speaker to "Beep" Alert the user if they get up to leave without noticing the boxes pop up boxes.

Like so, WshShell.Run "cmd /c @echo " & beep, 0

So was wondering if there is anyway to play a tune using the internal motherboard speaker, rather than a single or two beeps, something that gets there notice?

It needs to be the motherboard speaker beeping, because we have the sound disabled on the pc's generally.

Many thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top