' VBScript source code ' v1.0 - 5/3/2006 ' Script originally created to monitor a specified directory for the "._" files Mac OS X creates on SMB shares. ' Usage: cscript.exe dotunderscore.vbs C:\Temp ._. Note that if the folder name contains spaces, the entire path ' must be placed on quotation marks. ' ' This script can be started with a Scheduled Task in Windows. Set the task to start "At System Startup" on the Schedule ' tab. Make sure the user running the script has permissions on the folder to delete files. ' Set WshShell = WScript.CreateObject("WScript.Shell") Set Argument = WScript.Arguments Set objFSO = CreateObject("Scripting.FileSystemObject") strComputer = "." If Argument.Count < 2 Then WScript.Echo "This script will monitor a specified directory and delete files based" WScript.Echo "on the string specified. Originally created to monitor directories" WScript.Echo "for the ._filename that OS X creates." WScript.Echo "" WScript.Echo "Usage: cscript.exe dotunderscore.vbs " WScript.Echo "Example: cscript.exe dotunderscore.vbs C:\Folder\Share ._" WScript.Echo "Example: cscript.exe dotunderscore.vbs ""C:\Documents and Settings\username"" ._" WScript.Echo "" WScript.Echo "Folders with spaces must be placed in quotation marks." WScript.Quit End If FolderMonitor = Argument.Item(0) FileDelete = Argument.Item(1) WScript.Echo "Starting up..." WScript.Echo "" WScript.Echo "Monitoring folder: " & FolderMonitor WScript.Echo "Monitoring for files with the string: " & FileDelete WScript.Echo "" FolderMonitor = Replace(FolderMonitor, "\", "\\\\") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=" & chr(34) & FolderMonitor & chr(34) & "'") WScript.Echo "Script startup complete. Waiting..." WScript.Echo "" Do Set objLatestEvent = colMonitoredEvents.NextEvent strReturned = objLatestEvent.TargetInstance.PartComponent strFilePath = Split(strReturned, "CIM_DataFile.Name=")(1) strFilePath = Replace(strFilePath, """", "") strFilePath = Replace(strFilePath, "\\", "\") Set objFile = objFSO.GetFile(strFilePath) Set File = objFile DeleteFiles(File) Loop Sub DeleteFiles(File) If InStr(File, "" & FileDelete & "") Then WScript.Echo "Deleting file " & File objFile.Delete End If End Sub