Read/Write Remote File using WMI C#

2019-03-06 00:48发布

问题:

I need to read and write(update) some remote machine file.I am able to find the remote file using WMI(System.Management) but not able to do read or updation on that.

Any help would be appreciated.

Thanks

Himanshu

回答1:

The WMI doesn't have any class (or method) to read or write the content of files. Only you can retrieve the metadata (FileName, Date, Size) of the files using the CIM_DataFile or you can do tasks like Copy, Rename, Delete or Compress files.



回答2:

First check your file access in premmisions and set user "Everyone" to Full Control then try it again.



回答3:

RRUZ is correct: WMI cannot copy or create files over a network. This is because it would require credential "hopping": http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx

However, a workaround was recently created by Stackoverflow.com user Frank White in C#, and the WMI logic ports directly to VBS. Here's his solution: WMI remote process to copy file

I ported it to a fully working VBScript: https://stackoverflow.com/a/11948096/1569434



标签: c# file wmi