先使用Wmi开通连接,再Copy文件 下面是sdk中的例子。 using System; using System.Management;// This example demonstrates how to connect to remote machine // using supplied credentials. class Sample_ConnectionOptions { public static int Main(string[] args) { ConnectionOptions options = new ConnectionOptions(); options.Username = UserName; //could be in domain\user format options.Password = SecurelyStoredPassword; ManagementScope scope = new ManagementScope( "\\\\servername\\root\\cimv2", options); try { scope.Connect(); ManagementObject disk = new ManagementObject( scope, new ManagementPath("Win32_logicaldisk='c:'"), null); disk.Get(); } catch (Exception e) { Console.WriteLine("Failed to connect: " + e.Message); } return 0; } }
再用Systm.IO就可以了。
//192.168.0.98/$D
下面是sdk中的例子。
using System;
using System.Management;// This example demonstrates how to connect to remote machine
// using supplied credentials.
class Sample_ConnectionOptions
{
public static int Main(string[] args) {
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //could be in domain\user format
options.Password = SecurelyStoredPassword;
ManagementScope scope = new ManagementScope(
"\\\\servername\\root\\cimv2",
options);
try {
scope.Connect();
ManagementObject disk = new ManagementObject(
scope,
new ManagementPath("Win32_logicaldisk='c:'"),
null);
disk.Get();
}
catch (Exception e) {
Console.WriteLine("Failed to connect: " + e.Message);
}
return 0;
}
}
或者使用net use命令: Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); string command = "net use " + remote + " " + pass + " /user:" + user; p.StandardInput.WriteLine(command); p.WaitForExit(1000); p.StandardInput.WriteLine("exit"); p.Dispose();