Wednesday, April 04, 2012 8:50 AM
Hello, Im new to wqsl query writing and Im working with an example that I found on google, but Im trying to modify it so I can check for the creation of a new file on a folder in a mapped network drive.
This is the query:
SELECT * FROM __InstanceCreationEvent WITHIN 10
WHERE TargetInstance ISA "CIM_DirectoryContainsFile" and
when I run this query I get an error saying the query is unparsable, I'm guessing it something to do with how I am referencing the mapped drive (k:\)
This is how I would navigate to the folder via windows explorer
Wednesday, April 04, 2012 11:51 AMModerator
The quotes look wrong. Are you attempting to escape embedded quotes with a backslash? Where do you enter this query? Is this all one string you assign to a property? In VBScript I would try:
strWQL = " SELECT * FROM __InstanceCreationEvent WITHIN 10 " _ & "WHERE TargetInstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= 'Win32_Directory.Name=k:\\\\Directory1\\\\SSIS\\\\\Universal\\\\FTP_In\\\\NewFilesDirectory'"
Note the final single quoted followed by a double quote. However, I've never seen TargetInstance.GroupComponent and a reference to Win32_Directory.Name within a quoted value.
Richard Mueller - MVP Directory Services
Wednesday, April 04, 2012 12:08 PM
Richard is close:
Yes - the embedded quotes have to be escaped in this case. The example is right off of teh MS WMI examples. The format for the WQL 'string' is MOF format andMOF rules. It is a simple varaion on 'C' string rules.
Count you slasshes very carefully. In one spot you have 5. They need to be in sets of two and double up becuse it is an embeded escaped quote. When WMI unwinds the query it will reduse to a single backslash.
This makes no sense: (\\backup)K:\Directory1\SSIS\Universal\FTP_In\NewFilesDirectory\
This method uses single quotes as an alternate to escaping the quotes and works better in VBScript.
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""k:\\\\Directory1\\\\SSIS\\\\Universal\\\\FTP_In\\\\NewFilesDirectory\""'")
If 'K' is not a physical drive you cannot use this. The directory must resolve to a physical drive on the local machine.
If this is being used in a MOF or in PowerShell then the rules are much different.
To get this working point it at a simple flder like c:\scripts and be sure all of your code works then switch to the more complex path.
Here is a good example with a discussion of some of the issues that you maty run into.