读书人

关于System.Management 拷贝文件到另一

发布时间: 2012-01-12 22:11:58 作者: rapoo

关于System.Management 拷贝文件到另一台机器的使用
下面是我的代码
'登陆远程机器
Dim options As New ConnectionOptions
options.Username = "MGY-MEDIA\\administrator "
options.Password = "123321 "

Dim scope As New ManagementScope( "\\192.168.1.15 ")
If Not scope.IsConnected Then
scope.Connect()
End If

'得到远程驱动盘
Dim options1 As _
New ObjectGetOptions(Nothing, New TimeSpan(0, 0, 0, 5), True)

Dim disk As New ManagementObject(scope, New ManagementPath( "Win32_logicaldisk= 'd: ' "), options1)
disk.Get()

'传输文件
File.Copy( "E:\my\wordFile\lqz.txt ", "\\192.168.1.15\D$\test\1.txt ", True)


运行时报如下错误:
异常详细信息: System.IO.IOException: 找不到网络路径。

源错误:


行 51: disk.Get()
行 52:
行 53: File.Copy( "E:\my\wordFile\lqz.txt ", "\\192.168.1.15\D$\test\1.txt ", True)
行 54:
行 55:

请高手指教~~~~~谢过先


[解决办法]
如果表示路径,你在这个函数的参数中应主当使用这个类:
ManagementPath 类

比如:

下面的示例演示 ManagementPath 类如何分析指向 WMI 对象的路径。该示例中分析的路径是指向一个类的实例的路径。

using System;
using System.Management;

public class Sample
{
public static void Main()
{

// Get the WMI class path
ManagementPath p =
new ManagementPath(
"\\\\ComputerName\\root " +
"\\cimv2:Win32_LogicalDisk.DeviceID=\ "C:\ " ");

Console.WriteLine( "IsClass: " +
p.IsClass);
// Should be False (because it is an instance)

Console.WriteLine( "IsInstance: " +
p.IsInstance);
// Should be True

Console.WriteLine( "ClassName: " +
p.ClassName);
// Should be "Win32_LogicalDisk "

Console.WriteLine( "NamespacePath: " +
p.NamespacePath);
// Should be "ComputerName\cimv2 "

Console.WriteLine( "Server: " +
p.Server);
// Should be "ComputerName "

Console.WriteLine( "Path: " +


p.Path);
// Should be "ComputerName\root\cimv2:
// Win32_LogicalDisk.DeviceId= "C: " "

Console.WriteLine( "RelativePath: " +
p.RelativePath);
// Should be "Win32_LogicalDisk.DeviceID= "C: " "

}
}

读书人网 >VB Dotnet

热点推荐