Hi,
I need to copy a file from a remote machine using wmi but i don't know how to define the path to my machine, below is the code that makes a copy of a file in the same machine, what should be the path if i wanted to copy it to my c:\example\ folder?
ManagementBaseObject inParams, outParams;
foreach (ManagementObject mo in queryCollection)
{
Console.WriteLine(mo["Name"].ToString());
inParams = mo.GetMethodParameters("Copy");
inParams["FileName"] = "c:\\example.config; <----------------- what can i put here so that it refers to my machine?
outParams = mo.InvokeMethod("Copy", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
-----EDIT:-----
So, i've searched and experimented the whole weekend and nothing.
When I execute this code i get "returnValue 9" wich according to the WMI documentation represents "Invalid object".
The operation is sucessfull if i try to copy between folder on the same machine.
I'm using Windows Server 2003 on both machines.
I don't know any other way to copy a file from the remote machine to my machine.
oq = new ObjectQuery(@"Select * from CIM_Datafile Where Extension = 'config' and Drive = 'c:' and FileName = 'machine' and path like '\\windows\\microsoft.net\\framework\\%\\config%'");
query = new ManagementObjectSearcher(ms, oq);
queryCollection = query.Get();
ManagementBaseObject inParams, outParams;
foreach (ManagementObject mo2 in queryCollection)
{
Console.WriteLine(mo2["Name"].ToString());
inParams = mo2.GetMethodParameters("Copy");
inParams["FileName"] = "\\\\ibm-server2003\\I$\\machine.config";
outParams = mo2.InvokeMethod("Copy", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
I need to copy a file from a remote machine using wmi but i don't know how to define the path to my machine, below is the code that makes a copy of a file in the same machine, what should be the path if i wanted to copy it to my c:\example\ folder?
ManagementBaseObject inParams, outParams;
foreach (ManagementObject mo in queryCollection)
{
Console.WriteLine(mo["Name"].ToString());
inParams = mo.GetMethodParameters("Copy");
inParams["FileName"] = "c:\\example.config; <----------------- what can i put here so that it refers to my machine?
outParams = mo.InvokeMethod("Copy", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
-----EDIT:-----
So, i've searched and experimented the whole weekend and nothing.
When I execute this code i get "returnValue 9" wich according to the WMI documentation represents "Invalid object".
The operation is sucessfull if i try to copy between folder on the same machine.
I'm using Windows Server 2003 on both machines.
I don't know any other way to copy a file from the remote machine to my machine.
oq = new ObjectQuery(@"Select * from CIM_Datafile Where Extension = 'config' and Drive = 'c:' and FileName = 'machine' and path like '\\windows\\microsoft.net\\framework\\%\\config%'");
query = new ManagementObjectSearcher(ms, oq);
queryCollection = query.Get();
ManagementBaseObject inParams, outParams;
foreach (ManagementObject mo2 in queryCollection)
{
Console.WriteLine(mo2["Name"].ToString());
inParams = mo2.GetMethodParameters("Copy");
inParams["FileName"] = "\\\\ibm-server2003\\I$\\machine.config";
outParams = mo2.InvokeMethod("Copy", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}