|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - Monitor share for new file
I found the below code in the MS script repository can it be modified to monitor a network share or can it only run locally?
I have a NAS which is our file server and I need to know whena new file is deposited on one of the shares. Code:
strComputer = "."
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=""c:\\\\scripts""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop
Thank you VBSnoob |
|
#2
|
||||
|
||||
|
I'm pretty certain that an event-driven WMI script can only be run locally. This would need to run on the server.
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#3
|
|||
|
|||
|
Quote:
Thanks Nilpo, Is there another method you might recommend? |
|
#4
|
||||
|
||||
|
Quote:
The first being the obvious, write a WMI event script and run it locally on the server. You can write events to a text log or database and check them remotely. The second, would be to use the FileSystemObject. Since this can be used against remote directories, you could create a simple timer script that checks the file count for a given directory. Changes in this number would indicate a new file. It wouldn't be exactly real-time, but it could be close. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript - Monitor share for new file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|