读书人

C#调用cmd.exe程序,如何启动不了

发布时间: 2012-01-07 21:41:55 作者: rapoo

C#调用cmd.exe程序,怎么启动不了?
初学C#语言,不是很懂,请高人指点!!先谢谢了!!!
这里我要备份数据库,调用CMD,用命令方法备份,我代码如下,但是运行后发现CMD没有启动,是什么原因啊??
sqlbf();
//sqlbf dbop = new sqlbf();
//dbop.DbBackup();
string path = CreatePath();

string ls_dmp = CreatePath() + ".dmp ";
string ls_log = CreatePath() + ".log ";
string ls_name = uid;
string ls_pwd = pwd;
string ls_tns = server;
string ls_cmd = "exp " + ls_name + "/ " + ls_pwd + "@ " + ls_tns + " file= " + ls_dmp + " log= " + ls_log + " owner=(gdzc) ";

//开始创建文件
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
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(ls_cmd);
p.StandardInput.WriteLine( "exit ");
//string ls_ret = p.StandardOutput.ReadToEnd();

Label1.Text = "提示:数据库备份成功! ";
Response.Write( " <script> alert( ' " + Label1.Text + " '); </script> ");
p.Close();


}
catch (Exception err)
{
Label1.Text = "提示:数据库备份失败! " + err.Message;
Response.Write( " <script> alert( ' " + Label1.Text + " '); </script> ");
}

[解决办法]
p.StartInfo.CreateNoWindow = true;

这是控制不显示窗口的,设成false应该是显示.
[解决办法]
p.StartInfo.CreateNoWindow = false ;
[解决办法]
up
[解决办法]
p.StartInfo.CreateNoWindow设为false
[解决办法]
代码没发现任何问题,会不会是权限造成的,你确定你的网页有权限启动cmd?

读书人网 >C#

热点推荐