2016-11-15 131 views
0

我收到以下错误:输入字符串的不在WQL查询正确的格式

[WMI Event Watcher Task] Error: An error occurred with the following error message: "Input string was not in a correct format.".

当我执行WQL Query

SELECT * FROM __InstanceCreationEvent WITHIN 10 
WHERE TargetInstance ISA 'CIM_DataFile' AND TargetInstance.Name ='C:\\Users\Mohammed\\Desktop\\Test\\ETL\\ssis-basic-control-flow-tasks\\file_to_watch.txt' 

我尝试观看这样的文件:

enter image description here

回答

0
//Removes local network printer based 
    //on full unc path returns true if successful 
    //otherwise false 

    public static bool RemoveUnc(string printUncPath) 
    { 
     ManagementScope oManagementScope = new ManagementScope(ManagementPath.DefaultPath); 
     oManagementScope.Connect(); 

     SelectQuery oSelectQuery = new SelectQuery(); 
     oSelectQuery.QueryString = @"SELECT * FROM Win32_Printer WHERE Name = '" + 
      printUncPath.Replace("\\", "\\\\") + "'"; 

     ManagementObjectSearcher oObjectSearcher = 
      new ManagementObjectSearcher(oManagementScope, oSelectQuery); 

     ManagementObjectCollection oObjectCollection = oObjectSearcher.Get(); 

     if (oObjectCollection.Count != 0) 
     { 
      foreach (ManagementObject oItem in oObjectCollection) 
      { 
       oItem.Delete(); 
       return true; 
      } 
     } 
     return false; 
    } 

我假设它是包含引起错误的斜杠的字符串。以下是我用于从本地工作站中删除打印机的示例。打印机共享名称包含“\\ printserver \ printerShare”之类的格式。请注意printUncPath.Replace(“\\”,“\\\\”)。认为这将解决您的问题。很确定你必须逃脱两次。