'prepare the sink event Set oWMIServices=GetObject("winmgmts:\\.\root\CIMV2") ' . means monitor this computer set oSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_") 'create sink event oWMIServices.ExecNotificationQueryasync oSink, "SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_diskdrive' and TargetInstance.Interfacetype='USB'" While (TRUE) WScript.Sleep (1000) Wend Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext) sText=lcase(wmiObject.GetObjectText_()) iDevice=instr(sText,"deviceid") ' find the deviceid line ieqpos=instr(iDevice,sText,"=")+1 'on this line, look for = sign iSemiColon=instr(iEqPos,sText,";")'and semi-colin at end sDevice=trim(mid(sText,iEqPos,iSemiColon-iEqPos)) 'extract the name of the device and trim off spaces sDevice=replace(sDevice,"""","") 'remove the double quotes by replacing with nothing GetPartitions sDevice End Sub Sub GetPartitions(sDrive) Set oWMIServices = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//.") ' Get physical disk drive Set wmiDiskDrives = oWMIServices.ExecQuery ("SELECT Caption, DeviceID FROM Win32_DiskDrive where deviceid='" & sDrive & "'") For Each wmiDiskDrive In wmiDiskDrives 'Use the disk drive device id to find associated partition query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _ & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" Set wmiDiskPartitions = oWMIServices.ExecQuery(query) For Each wmiDiskPartition In wmiDiskPartitions 'Use partition device id to find logical disk Set wmiLogicalDisks = oWMIServices.ExecQuery ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _ & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") For Each wmiLogicalDisk In wmiLogicalDisks CheckFolder(wmiLogicalDisk.DeviceID & "\") Next Next Next end sub Sub CheckFolder(sFolder) 'this routine is called with (eg) G:\ or H:\ 'it is called for the root folder of each partition on the USB stick end sub