2016-11-15 54 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(「\\」,「\\\\」)。認爲這將解決您的問題。很確定你必須逃脫兩次。