Thursday, July 30, 2009

How can i start a process("cmd.exe") using c#.NET?

Command prompt must be invisible ( run in background ) %26amp; I want to run a command in it Invicibley ("copy c:\text.txt a:\ ").





I use ' System.diognatics.process.start("cmd.exe... ' It execute the process but i cannot make it invisible.





Also i need to change the path on the command prompt with coding.


can i use a batch file also to this?





please help me with c#.net code.

How can i start a process("cmd.exe") using c#.NET?
Use this Code;








public static int executeCommand(string cmd, int millsecTimeOut)


{


System.Diagnostics.ProcessStartInfo processStartInfo =


new System.Diagnostics.ProcessStartInfo("CMD... "/C "+cmd);


processStartInfo.CreateNoWindow = true;


processStartInfo.UseShellExecute = false;


System.Diagnostics.Process process =


System.Diagnostics.Process.Start(proce...


process.WaitForExit(millsecTimeOut); //wait for 20 sec


int exitCode = process.ExitCode;


process.Close();


return exitCode;


}
Reply:You can't.





Use the File.Copy() method instead.


No comments:

Post a Comment