【问题标题】:Input string was not in a correct format in WQL queryWQL 查询中的输入字符串格式不正确
【发布时间】:2017-03-28 21:44:03
【问题描述】:

我收到以下错误:

[WMI 事件观察程序任务] 错误:发生以下错误 错误消息:“输入字符串的格式不正确。”。

当我执行 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'

我尝试观看这样的文件:

【问题讨论】:

  • 我假设你的路径是C:\Users\Mohammed\Desktop。在这种情况下,您需要将每个反斜杠替换为 4 个反斜杠,例如 C:\\\\Users\\\Mohammed\\\\Desktop。对路径的其余部分执行相同操作。

标签: ssis wmi ssis-2012 wmi-query wql


【解决方案1】:
    //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("\\","\\\\")。认为这将解决您的问题。很确定你必须逃脱两次。

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2013-08-22
    相关资源
    最近更新 更多