|
-
Aug 13th, 2006, 01:49 PM
#1
Thread Starter
PowerPoster
WMI C# help
I'm new to WMI/C# using the System.Management namespace.
basically, I want to retrieve a list of files from a remote computer (local network). I can get this done but the next stage is to copy a specific file over from the computer to a local folder....
how would I do this?
Code:
System.Text.StringBuilder sb = new StringBuilder();
ConnectionOptions oConn = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\server\\root\\cimv2", oConn);
sb.Append("SELECT * FROM CIM_Datafile WHERE Extension = 'config'");
ObjectQuery oQuery = new ObjectQuery(sb.ToString());
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(scope, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
int rowCount = 0;
foreach (ManagementObject oReturn in oReturnCollection)
{
rowCount++;
MessageBox.Show(oReturn["Name"].ToString());
}
-
Aug 14th, 2006, 01:56 AM
#2
New Member
Re: WMI C# help
You can use the WMI methods for copying files. The WMI class CIM_DataFile has Copy and CopyEx methods which you can use to copy files using WMI. You might want to use CopyEx since you can have a recursive mode of copying.
Also, I think you can just copy the files using the other classes of the .NET framework. Just do what you think is easier.
-
Aug 14th, 2006, 08:24 AM
#3
Thread Starter
PowerPoster
Re: WMI C# help
well I cant do it from .NET as .NET will not accept UNC paths hence why I had to go to WMI
I tried CopyFile, seemed to have worked but nothing was copied
-
Aug 14th, 2006, 08:41 PM
#4
New Member
Re: WMI C# help
 Originally Posted by Techno
well I cant do it from .NET as .NET will not accept UNC paths hence why I had to go to WMI
I tried CopyFile, seemed to have worked but nothing was copied
Have you tried CopyEx?? how did you code that one??
-
Aug 14th, 2006, 09:21 PM
#5
Thread Starter
PowerPoster
Re: WMI C# help
actually i managed to get it EXCEPT that it wont copy the file! (using copy or copyex) nothing happens, no exceptions, nothing.
oReturn.InvokeMethod("Copy", new object[] { oReturn["Name"], "\\LocalComp\\C$"});
-
Aug 15th, 2006, 11:21 PM
#6
New Member
Re: WMI C# help
I believe the third parameter of the InvokeMethod is for the InvokeMethodOptions class. What .NET framework are you using??
-
Aug 24th, 2006, 11:50 AM
#7
Thread Starter
PowerPoster
Re: WMI C# help
ive actually got this to work now, thanks. I do have another Q though, I want to now invoke a process, start a process (run an app) - how would I do this in C# and WMI? I know in WMI there is a Create process, but how do I invoke this in C#?
-
Apr 23rd, 2007, 02:23 AM
#8
New Member
Re: WMI C# help
Please send me the code that worked for the copy, as I can't do it till now, I have the same problem and my code doesn't work
-
May 7th, 2008, 04:39 PM
#9
New Member
Re: WMI C# help
 Originally Posted by Techno
ive actually got this to work now, thanks. I do have another Q though, I want to now invoke a process, start a process (run an app) - how would I do this in C# and WMI? I know in WMI there is a Create process, but how do I invoke this in C#?
It is customary to share with the forum the solution that worked for you. Otherwise, this post is just google-spam (A search that yields my problem, but not my solution).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|