I'm trying to process files that are placed in a mapped network folder. Once
a file is copied into the folder, I would like to check the filename against
a list of known files, move it, rename it and process it.

I was trying to get this example to work for me:

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

But the objLatestEvent.TargetInstancePartComponent seems to be a string
rather than an object. In other words, I can't do
objLatestEvent.TargetInstance.PartComponent.Name , etc...

Any ideas?

TIA,
Chester

Re: How to access files from CIM_DirectoryContainsFile by Torgeir

Torgeir
Thu Jul 21 14:31:03 CDT 2005

chester wrote:

> I'm trying to process files that are placed in a mapped network folder. Once
> a file is copied into the folder, I would like to check the filename against
> a list of known files, move it, rename it and process it.
>
> I was trying to get this example to work for me:
>
> 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
>
> But the objLatestEvent.TargetInstancePartComponent seems to be a string
> rather than an object. In other words, I can't do
> objLatestEvent.TargetInstance.PartComponent.Name , etc...
>
> Any ideas?
Hi,

Parse the string:


'--------------------8<----------------------

Set objFSO = CreateObject("Scripting.FileSystemObject")

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
strReturned = objLatestEvent.TargetInstance.PartComponent
strFilePath = Split(strReturned, "CIM_DataFile.Name=")(1)
strFilePath = Replace(strFilePath, """", "")
strFilePath = Replace(strFilePath, "\\", "\")
Set objFile = objFSO.GetFile(strFilePath)
WScript.Echo objFile.Name
Loop

'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: How to access files from CIM_DirectoryContainsFile by chester

chester
Thu Jul 21 17:20:04 CDT 2005

"Torgeir Bakken (MVP)" wrote:
> Parse the string:
> 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)
> WScript.Echo objFile.Name
> Loop

Thanks! I just found it strange that it didn't return what I would have
expected to be a class. Is this true everywhere else? Sorry, I'm a n00b.

Thanks,
Chester