前言:
IDM是国外的一款收费下载工具,网上可以找到绿色版,比迅雷下载速度要快一点,并且支持文件重命名,迅雷目前没有找到文件重命名的方法。QQ旋风也支持文件重命名,但是QQ旋风跑一段时间会崩溃,并且有的文件下载不下来,必须手动点击下载,等等问题目前无法解决。
cmd命令执行方法:
public static void RunCmd(string cmd) { string CmdPath = @"C:\Windows\System32\cmd.exe"; cmd = cmd.Trim().TrimEnd('&') + "&exit";//要加exit命令,否则后面调用ReadtoEnd()命令会假死 using (Process p = new Process()) { p.StartInfo.FileName = CmdPath; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine(cmd); p.StandardInput.AutoFlush = true; p.WaitForExit(); p.Close(); } }
调用:
string sIDMPath = @"E:\Software\idman_lv\IDM\IDMan.exe"; string sDownloadPath="http://pan.baidu.com/s/...";//网盘链接 string sOutPutPath = @"D:\TempFolder\"; string sFileName= Guid.NewGuid().ToString()+".pdf"; string sCmd = string.Format(@"{0} /d ""{1}"" /p ""{2}"" /f ""{3}""", sIDMPath, sDownloadPath, sOutPutPath, sFileName); CmdBox.AppendText(sCmd + "\n"); SqlProcs.RunCmd(sCmd);
注释:
1.如果调用程序路径中有空格时,cmd命令执行失败,可以用双引号括起来
2.阻止IDM弹出开始下载、下载完成、重复文件询问窗口
3.如何以管理员身份运行程序请参考http://www.cnblogs.com/babycool/p/3569183.html