public static void OpenDirectory(string str_Directory,string to_Directory, string str_UserName, string str_Password)
{
string str_LogoOn = "net use " + str_Directory + " /user:" + str_UserName + " \"" + str_Password + "\"";
string str_OpenDirectory = "start " + str_Directory;
Process p_Tmp = new Process();
p_Tmp.StartInfo.RedirectStandardError = true;
p_Tmp.StartInfo.RedirectStandardInput = true;
p_Tmp.StartInfo.RedirectStandardOutput = true;
p_Tmp.StartInfo.UseShellExecute = false;
p_Tmp.StartInfo.CreateNoWindow = true;
p_Tmp.StartInfo.FileName = "cmd.exe";
p_Tmp.Start();
p_Tmp.StandardInput.WriteLine(str_LogoOn);
p_Tmp.StandardInput.WriteLine(str_OpenDirectory);
p_Tmp.StandardInput.WriteLine("exit");
p_Tmp.Close();
p_Tmp.Dispose();
string[] files = Directory.GetFiles(fromDirectory);
if (files.Length > 0)
{
foreach (string s in files)
{
FileInfo objFI = new System.IO.FileInfo(s);
File.Copy(str_Directory + "\\" + objFI.Name.ToString(), to_Directory + "\\" + objFI.Name.ToString());
}
}
}
調用如下﹕{
string str_LogoOn = "net use " + str_Directory + " /user:" + str_UserName + " \"" + str_Password + "\"";
string str_OpenDirectory = "start " + str_Directory;
Process p_Tmp = new Process();
p_Tmp.StartInfo.RedirectStandardError = true;
p_Tmp.StartInfo.RedirectStandardInput = true;
p_Tmp.StartInfo.RedirectStandardOutput = true;
p_Tmp.StartInfo.UseShellExecute = false;
p_Tmp.StartInfo.CreateNoWindow = true;
p_Tmp.StartInfo.FileName = "cmd.exe";
p_Tmp.Start();
p_Tmp.StandardInput.WriteLine(str_LogoOn);
p_Tmp.StandardInput.WriteLine(str_OpenDirectory);
p_Tmp.StandardInput.WriteLine("exit");
p_Tmp.Close();
p_Tmp.Dispose();
string[] files = Directory.GetFiles(fromDirectory);
if (files.Length > 0)
{
foreach (string s in files)
{
FileInfo objFI = new System.IO.FileInfo(s);
File.Copy(str_Directory + "\\" + objFI.Name.ToString(), to_Directory + "\\" + objFI.Name.ToString());
}
}
}
OpenDirectory(@"c:\11",@"\\cqccri-tianbing\d$\22","administrator","sima");