public bool ProcessXCopy()
{
string XCopyArguments = "yourargumentshere";
Process XCopyProcess = new Process();
ProcessStartInfo XCopyStartInfo = new ProcessStartInfo();
XCopyStartInfo.FileName = "CMD.exe ";
//do not write error output to standard stream
XCopyStartInfo.RedirectStandardError = false;
//do not write output to Process.StandardOutput Stream
XCopyStartInfo.RedirectStandardOutput = false;
//do not read input from Process.StandardInput (i/e; the keyboard)
XCopyStartInfo.RedirectStandardInput = false;
XCopyStartInfo.UseShellExecute = false;
//Dont show a command window
XCopyStartInfo.CreateNoWindow = true;
XCopyStartInfo.Arguments = "/D /c XCOPY " + XCopyArguments;
XCopyProcess.EnableRaisingEvents = true;
XCopyProcess.StartInfo = XCopyStartInfo;
//start cmd.exe & the XCOPY process
XCopyProcess.Start();
//set the wait period for exiting the process
XCopyProcess.WaitForExit(15000); //or the wait time you want
int ExitCode = XCopyProcess.ExitCode;
bool XCopySuccessful = true;
//Now we need to see if the process was successful
if (ExitCode > 0 & !XCopyProcess.HasExited)
{
XCopyProcess.Kill();
XCopySuccessful = false;
}
//now clean up after ourselves
XCopyProcess.Dispose();
StartInfo = null;
return XCopySuccessful;
}
Взято с http://www.dreamincode.net
0.00 (0%) 0 votes








