/// <summary> /// Dirコマンドフォルダーリスト出力 /// </summary> /// <param name="srcpath"></param> /// <param name="exportpath"></param> void XCopy(string srcpath, string exportpath) { StringBuilder dircommand = new StringBuilder(); Process defaultUserDeskTop = new Process(); try { // コマンド処理 dircommand.Append("xcopy /s /h /d /c /y /J "); dircommand.Append("\"" + srcpath + "\" "); dircommand.Append("\"" + exportpath + "\""); // BAT作成 string batFileName = "XCOPY-" + Common.RandomCode.GetCode(16) + ".bat"; string batDir = DateTime.Now.ToString("yyyy-MM-dd") + "Bat"; // 今のプログラムパス string batPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir + "\\" + batFileName; CreateBAT batClass = new CreateBAT(batPath); batClass.Write(dircommand.ToString()); defaultUserDeskTop.StartInfo.FileName = batPath; defaultUserDeskTop.StartInfo.UseShellExecute = true; //defaultUserDeskTop.StartInfo.RedirectStandardInput = true; //defaultUserDeskTop.StartInfo.RedirectStandardOutput = true; defaultUserDeskTop.StartInfo.CreateNoWindow = true; //defaultUserDeskTop.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; defaultUserDeskTop.Start(); //defaultUserDeskTop.StandardInput.WriteLine("exit"); //defaultUserDeskTop.WaitForExit(); //defaultUserDeskTop.Close(); } catch (Exception ex) { logger.Error(ex.Message); } }
/// <summary> /// Dirコマンドフォルダーリスト出力 /// </summary> /// <param name="monitorID"></param> /// <param name="srcpath"></param> /// <param name="exportpath"></param> /// <param name="listentime"></param> /// <param name="threadnum"></param> /// <param name="retrynum"></param> /// <param name="retrytime"></param> void CopyListen(string srcpath, string exportpath, string listentime, string threadnum, string retrynum, string retrytime) { StringBuilder dircommand = new StringBuilder(); Process defaultUserDeskTop = new Process(); try { // 配置ファイル名 string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "-" + Common.RandomCode.GetCode(16) + ".log"; string datenowDir = DateTime.Now.ToString("yyyy-MM-dd"); // 今のログパス string logpath = System.AppDomain.CurrentDomain.BaseDirectory + datenowDir + "\\" + fileName; LogFile(logpath); // コマンド処理 dircommand.Append("robocopy "); dircommand.Append("\"" + srcpath + "\" "); dircommand.Append("\"" + exportpath + "\" "); dircommand.Append(" /MIR "); //dircommand.Append(" /MOT:" + listentime + " "); dircommand.Append(" /MT[:" + threadnum + "] "); dircommand.Append(" /R:" + retrynum + " "); dircommand.Append(" /W:" + retrytime + " "); dircommand.Append(" /LOG+:"); dircommand.Append("\"" + logpath + "\""); dircommand.Append(" /NP /NDL /TEE /XJD /XJF "); // BAT作成 string batFileName = "ROBOCOPY-" + Common.RandomCode.GetCode(16) + ".bat"; string batDir = DateTime.Now.ToString("yyyy-MM-dd") + "Bat"; // 今のプログラムパス string batPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir + "\\" + batFileName; CreateBAT batClass = new CreateBAT(batPath); batClass.Write(dircommand.ToString()); // プロセス設定 defaultUserDeskTop.StartInfo.FileName = batPath; defaultUserDeskTop.StartInfo.UseShellExecute = true; //defaultUserDeskTop.StartInfo.RedirectStandardInput = true; //defaultUserDeskTop.StartInfo.RedirectStandardOutput = true; defaultUserDeskTop.StartInfo.CreateNoWindow = true; //defaultUserDeskTop.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; defaultUserDeskTop.Start(); // 転送のプロセスIDの保存(CMD) processIDList.Add(defaultUserDeskTop.Id); //defaultUserDeskTop.StandardInput.WriteLine("exit"); //defaultUserDeskTop.WaitForExit(); //defaultUserDeskTop.Close(); } catch (Exception ex) { logger.Error(ex.Message); } }
/// <summary> /// Dirコマンドフォルダーリスト出力 /// </summary> /// <param name="srcpath"></param> /// <param name="exportpath"></param> /// <param name="listentime"></param> /// <param name="threadnum"></param> /// <param name="retrynum"></param> /// <param name="retrytime"></param> void CopyListen(string srcpath, string exportpath, string listentime, string threadnum, string retrynum, string retrytime) { StringBuilder dircommand = new StringBuilder(); Process defaultUserDeskTop = new Process(); try { // 配置ファイル名 string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "-" + RandomCode.GetCode(10) + ".log"; string datenowDir = DateTime.Now.ToString("yyyy-MM-dd"); // 今のログパス string logpath = System.AppDomain.CurrentDomain.BaseDirectory + datenowDir + "\\" + fileName; LogFile(logpath); // コマンド処理 dircommand.Append("robocopy "); dircommand.Append("\"" + srcpath + "\" "); dircommand.Append("\"" + exportpath + "\" "); dircommand.Append(" /MIR "); dircommand.Append(" /MOT:" + listentime + " "); dircommand.Append(" /MT[:" + threadnum + "] "); dircommand.Append(" /R:" + retrynum + " "); dircommand.Append(" /W:" + retrytime + " "); dircommand.Append(" /LOG+:"); dircommand.Append("\"" + logpath + "\""); dircommand.Append(" /NP /NDL /TEE /XJD /XJF "); // BAT作成 string batFileName = RandomCode.GetCode(10) + ".bat"; string batDir = DateTime.Now.ToString("yyyy-MM-dd") + "Bat"; // 今のプログラムパス string batPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir + "\\" + batFileName; CreateBAT batClass = new CreateBAT(batPath); batClass.Write(dircommand.ToString()); //// プロセス設定 //defaultUserDeskTop.StartInfo.UserName = "******"; //System.Security.SecureString password = new System.Security.SecureString(); //char[] pass = "******".ToCharArray(); //foreach (char c in pass) //{ // password.AppendChar(c); //} //defaultUserDeskTop.StartInfo.Password = password; // defaultUserDeskTop.StartInfo.FileName = "cmd.exe"; defaultUserDeskTop.StartInfo.UseShellExecute = false; defaultUserDeskTop.StartInfo.RedirectStandardInput = true; defaultUserDeskTop.StartInfo.RedirectStandardOutput = true; defaultUserDeskTop.StartInfo.CreateNoWindow = true; defaultUserDeskTop.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; if (defaultUserDeskTop.Start()) { defaultUserDeskTop.StandardInput.WriteLine(dircommand); ProcessIDList.Add(defaultUserDeskTop.Id); } //defaultUserDeskTop.StandardInput.WriteLine("exit"); //defaultUserDeskTop.WaitForExit(); //defaultUserDeskTop.Close(); } catch (Exception ex) { logger.Error(ex.Message); } }