日期:2014-05-20  浏览次数:21183 次

.Net中,文件Copy可否带什么验证
WinForm程序,目的是从机器A拷贝文件到机器B,已经知道机器B的管理员密码。机器A,B是同一个组,都是XP的系统。

现在程序使用File.Copy,但因为权限问题而操作不成功。

各位是否有好方法

------解决方案--------------------
如果你是一个局域网,必须用文件共享,才能进行IO操作
public static bool NetUse(string ip,string uid,string pwd)
{

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();
byte[] buffer = Convert.FromBase64String(pwd);
pwd = System.Text.UTF8Encoding.Default.GetString(buffer);
string cmdText= "net use \\\\ "+ip+ " "+pwd+ " /USER: "+uid;
p.StandardInput.WriteLine(cmdText);

p.StandardInput.WriteLine( "exit ");
string strRst = p.StandardOutput.ReadToEnd();
p.Close();
if(strRst.IndexOf( "命令成功完成 ")!=-1)
return true;
return false;
}
IO操作之前先运行上面函数 ,就可以了像本地一样了
------解决方案--------------------
FromBase64String()
是我这里的使用方法,你换成你自己的,直接传名文就可以
共享要事先设置好才可以