J'utilise mgmtclassgen.exe et récupère la classe wrapper (DataFile.cs) pour la classe wmi CIM_DataFile. Le code ci-dessous fonctionne parfaitement sur localhost (sans remplir de credentionals), mais quand je me connecte à la variable machine distante returnResult = 9 (objet invalide). Mais la taille de dataFileCollection variable = 1wmi C#. copie le fichier de la machine distante
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);
}
}
}