【问题标题】:find a Particular product present in a remote system or not查找远程系统中是否存在特定产品
【发布时间】:2008-11-19 14:02:29
【问题描述】:

尝试查找产品是否安装在远程PC中,执行需要很长时间, 有什么方法可以让我们更快地实现这一目标。

//用法: //uninstall4("主机名", "产品名", "{AC9C1263-2BA8-4863-BE18-01232375CE42}", "10.0.0.69");

    public void uninstall4(string targetServer, string product,string guid , string version)
    {
        //Connect to Server
        System.Management.ConnectionOptions connoptions = new System.Management.ConnectionOptions();
        connoptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
        connoptions.Timeout = new TimeSpan(0, 0, 10); // 10 seconds
        System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + targetServer + @"\root\cimv2", connoptions);
        scope.Connect();

        string q = "select * from Win32_Product where name = '" + product + "' and IdentifyingNumber='"+guid+"' and version = '"+version+"'";

        System.Management.SelectQuery query = new System.Management.SelectQuery(q);

        System.Management.EnumerationOptions options = new System.Management.EnumerationOptions();
        options.EnumerateDeep = false;
        options.ReturnImmediately = false;
        options.DirectRead = true;

        using (System.Management.ManagementObjectSearcher searcher
            = new System.Management.ManagementObjectSearcher(scope, query, options))
        {
            using (System.Management.ManagementObjectCollection moc = searcher.Get())
            {
                if(moc == null || moc.Count == 0)
                {
                    throw new Exception("product Not Found");
                }

            }
        }

    }

【问题讨论】:

    标签: wmi


    【解决方案1】:

    不。 Win32_Product 类的提供程序必须在您查询时动态构建信息,而且它总是很慢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 2021-12-11
      相关资源
      最近更新 更多