【问题标题】:wmi c#. copy file from remote machinewmi c#.从远程机器复制文件
【发布时间】:2012-10-31 20:41:53
【问题描述】:

我使用 mgmtclassgen.exe 并为 CIM_DataFile wmi 类获取 wrapper(DataFile.cs) 类。下面的代码在 localhost 上完美运行(不填充凭证),但是当我连接到远程机器变量 returnResult=9 (无效对象)时。但是变量dataFileCollection的大小=1

var _connectionOptions = new ConnectionOptions();
                _connectionOptions.Username = "username";
                _connectionOptions.Password = "password";
                _connectionOptions.Authority = String.Format("ntlmdomain:{0}", "DOMAIN");
var _managementScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2",  
"RemotePCName"), _connectionOptions);
    var dataFileCollection = DataFile.GetInstances(_managementScope,
                    @"Name = 'C:\\Windows\\System32\\mapisvc.inf'";
                var tempFilePath =  "c:\\temp.txt");
                if (dataFileCollection.Count > 0)
                {
                    foreach (var dataFile in dataFileCollection.Cast<DataFile>())
                    {
                        var returnResult = dataFile.Copy(tempFilePath);
                        if (File.Exists(tempFilePath))
                        {
                            List<string> lines = File.ReadAllLines(tempFilePath).ToList();
                            File.Delete(tempFilePath);
                        }
                    }
                }

【问题讨论】:

    标签: c# copy wmi remote-server


    【解决方案1】:

    尝试以不同方式调整您的管理范围 也许你可以试试:

    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher(
                            "\\\\" + strComputer + "\\root\\CIMV2",
                            "SELECT * FROM Win32_PerfFormattedData_MSSQLSERVER_SQLServerDatabases");
    

    其中 strComputer 是远程 pc 的名称和 Win32_Perf...您要查询的类。这对我有用,因为它在本地网络中,但我不确定您的远程计算机位于何处。

    您也可以使用http://www.microsoft.com/en-us/download/details.aspx?id=8572,它是 Microsoft 的 WMI 查询生成器。这允许您在 C#、VB 和 VB 脚本中生成查询。在设置连接属性时。 可能值得一试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      相关资源
      最近更新 更多