I wish to search for recently modified text file which has Indicator in the filename on remote machine in same domain. The (UNC) path for the directory looks like
\\MachineName\Applications\Indicator\myFolder
I tried something like this :
ConnectionOptions options = new ConnectionOptions();
options.Username = username;
options.Password = password;
ManagementScope scope = new ManagementScope("\\\\MachineName\\root\\cimv2", options);
scope.Connect(); // returns true i.e IsConnected=true
ObjectQuery query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile where path=\\MachineName\Applications\Indicator\myFolder"); //This query is just for trial purpose.
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get(); //Code breaks here
I get the following error :
'queryCollection.Count' threw an exception of type
'System.Management.ManagementException'
Message is InvalidQuery
Can someone help me with 2 things:
Why is this simple code breaking?
Can someone help me with WMI query to get the recently modified file in the specified directory?
PS: Please let me know if any additional info is needed. Thanks!