public static void downLoadFile(string name) { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; //关闭Shell的使用 p.StartInfo.UseShellExecute = false; //重定向标准输入 p.StartInfo.RedirectStandardInput = true; //重定向标准输输出 p.StartInfo.RedirectStandardOutput = true; //重定向错误输出 p.StartInfo.RedirectStandardError = true; //设置不显示窗口 p.StartInfo.CreateNoWindow = true; p.Start(); //切换用户 获取管理员权限 string switchU = @"runas /user:administrator cmd"; string pwd = @"feifan"; //直接登陆后映射服务器 F:\MyTime 到本地为 Z string dosLine1 = @"net use z: \\172.29.132.127\F$ 密码 /USER:administrator"; //下载 string dosLine2 = @"copy z:\MyTime\" + name + " " + name + " /y"; //删除映射 string delMap = @"net use Z: /del"; //删除连接 string delCon = @"net use \\172.29.132.127\ipc$ /del";
p.StandardInput.WriteLine(switchU); Thread.Sleep(50); //一定要加延迟 p.StandardInput.WriteLine(pwd); Thread.Sleep(50); p.StandardInput.WriteLine(dosLine1); Thread.Sleep(50); p.StandardInput.WriteLine(dosLine2); Thread.Sleep(1000); p.StandardInput.WriteLine(delMap); Thread.Sleep(50); p.StandardInput.WriteLine(delCon); }
|