Sajal wanted to monitor a directory, detect new file(s) and open them in their associated applications, I remember monitoring directory for changes in Linux in a Perl script. Doing something similar on Windows it seemed tough, but a after a little pondering I remembered about Windows Script Host (WSH), and after a bit of googling, coding, trial and errors, I came up with a script which does all that is required, it’s written in VBScript.
[vb]
strDrive = “D:”
strFolder = “\\dropbox\\downloads\\”
strComputer = “.”
intInterval = “5”
‘ Connect WMI service
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\cimv2”)
‘ build query
strQuery = “Select * From __InstanceCreationEvent” _
& ” Within ” & intInterval _
& ” Where Targetinstance Isa ‘CIM_DataFile'” _
& ” And TargetInstance.Drive='” & strDrive & “‘”_
& ” And TargetInstance.Path='” & strFolder & “‘”
‘ Execute notification query
Set colMonitoredEvents = objWMIService.ExecNotificationQuery(strQuery)
‘ get a shell application object
Set WshShell = WScript.CreateObject(“Shell.Application”)
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
‘ strip out the real path
Response = Split(objLatestEvent.TargetInstance.PartComponent, “=”)
‘ remove slash & quotes
FileName = Replace(Response(1), “”””, “”)
FileName = Replace(FileName, “\\”, “\”)
‘ open the file in it’s associated program
WshShell.ShellExecute FileName, “”, “”, “open”, 1
Wscript.Echo FileName
Loop
[/vb]
While implementing Google AMP (Accelerated Mobile Pages) for your website, it might occur to you…
Thinking of buying the JioFi device by reliance or to be precise any device by…
Do you hate those pesky javascripts. Majority of the banking, utility bill payment etc so…
So amazon has this amazing feature called whispersync : If you read the same Kindle…
Getting a new HTC One left me wondering how will I move Google Authenticator from…
Get Bad Company 2, ME: Infiltrator, etc for free Free Games you can get today:…