wql query to access mapped network drive
-
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
TargetInstance.GroupComponent= "Win32_Directory.Name=\"k:\\\\Directory1\\\\SSIS\\\\\Universal\\\\FTP_In\\\\NewFilesDirectory\""
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
(\\backup)K:\Directory1\SSIS\Universal\FTP_In\NewFilesDirectory\
All Replies
-
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.
http://blogs.technet.com/b/heyscriptingguy/archive/2005/04/04/how-can-i-monitor-for-different-types-of-events-with-just-one-script.aspx
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Wednesday, April 04, 2012 12:09 PM
- Proposed As Answer by Richard MuellerMVP, Moderator Thursday, April 05, 2012 10:08 PM
- Marked As Answer by Richard MuellerMVP, Moderator Wednesday, April 11, 2012 10:18 PM

