Return just the file path and name

Return just the file path and name

Post by Mike Brear » Fri, 09 Dec 2005 06:21:38


How can I modify this so that it echo's just the file path and name? i.e.
returning just this: c:\scripts\test.txt instead of
\\servername\root\cimv2:CIM_DataFile.Name="c:\\scripts\\test.txt"

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

--
Posted 'as is'. If there are any spelling and/or grammar mistakes, they
were a direct result of my fingers and brain not being synchronized or my
lack of caffeine.
 
 
 

Return just the file path and name

Post by Jerold Sch » Fri, 09 Dec 2005 22:18:04


DIM MyArray
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
set strPath=objLatestEvent.TargetInstance.PartComponent
MyArray=Split(strPath, "=")
Wscript.Echo MyArray(1)
Loop

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.yqcomputer.com/
http://www.yqcomputer.com/

 
 
 

Return just the file path and name

Post by Mike Brear » Sat, 10 Dec 2005 03:39:42

Thanks...

I had to modify that a little so it looks like this:

DIM MyArray
DIM strPath
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
strPath = objLatestEvent.TargetInstance.PartComponent
MyArray=Split(strPath, "=")
Wscript.Echo MyArray(1)
Loop

--
Posted 'as is'. If there are any spelling and/or grammar mistakes, they
were a direct result of my fingers and brain not being synchronized or my
lack of caffeine.