Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.85 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WMI Search Wildcard returns nothing
  2. ManagementScope oScope = new ManagementScope("\\" + txtHostName +
  3.         "\root\CIMV2", oConn);
  4.  
  5.     string wheresub = "FileName Like '%myfile%'";
  6.  
  7.     ObjectQuery oQuery = new ObjectQuery(@"SELECT * FROM CIM_DataFile WHERE (" +
  8.         wheresub + ") AND (Drive = 'C:' OR Drive = 'D:' OR Drive = 'E:')");
  9.  
  10.     ManagementObjectSearcher searcher = new ManagementObjectSearcher(oScope, oQuery);
  11.  
  12.     Log("Searching...");
  13.  
  14.     foreach (ManagementObject queryObj in searcher.Get())
  15.     {
  16.         FilesFound++;
  17.         Log(String.Format("--> {0}{1}{2}.{3}", queryObj["Drive"], queryObj["Path"], queryObj["FileName"], queryObj["Extension"]));
  18.     }
  19.     if (FilesFound > 0)
  20.     {
  21.         Log(" " + FilesFound + " files found.");
  22.     }
  23.     else
  24.     {
  25.         Log(" Clean.");
  26.     }
  27.        
  28. string wheresub = "FileName = 'PROCID_myfile_1234'";