首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

.net施行CMD 用Wpdf2swf.exe转换文件总是不成功求解答

2013-01-02 
.net执行CMD 用Wpdf2swf.exe转换文件总是不成功求解答protected void Page_Load(object sender, EventArgs

.net执行CMD 用Wpdf2swf.exe转换文件总是不成功求解答

 

 protected void Page_Load(object sender, EventArgs e)
    {
         comm cm = new comm();
        //Response.Write(cm.RumCmd("ping www.baidu.com"));//可成功
        cm.RunProgram("C:\\Program Files\\SWFTools\\pdf2swf.exe", "test.pdf test1.swf");
    }
 public  class comm 
    {
       private Process p = null;
       public comm()
       {
           p = new Process();
       }
       /// <summary>
       /// 执行cmd命令
       /// </summary>
       /// <param name="cmd">需要执行的命令</param>
       /// <returns></returns>
       public string  RumCmd(string cmd)
       {
           string str = null;
           p.StartInfo.CreateNoWindow =true;
           p.StartInfo.FileName = "cmd.exe";
           p.StartInfo.UseShellExecute = false;
           p.StartInfo.RedirectStandardError = true; 
           p.StartInfo.RedirectStandardInput = true;
           p.StartInfo.RedirectStandardOutput = true; 
           p.Start();
           p.StandardInput.WriteLine(cmd);
           p.StandardInput.WriteLine("exit");
           p.WaitForExit();
           str = p.StandardOutput.ReadToEnd();
           p.Close();
           return str;
       }
       /// <summary>
       /// 通过CMD打开软件并执行相应命令
       /// </summary>
       /// <param name="programName"> 软件URL(.exe文件)</param>
       /// <param name="cmd">需要进行的操作</param>
       public void RunProgram(string programName,string cmd)  
       {   
           Process proc = new Process();   
           proc.StartInfo.CreateNoWindow = true;
//p.StartInfo.WorkingDirectory = "c:\\Documents and Settings\\Administrator\";


           //p.StartInfo.Arguments
           proc.StartInfo.FileName = programName;
           proc.StartInfo.Arguments = cmd;
           proc.StartInfo.UseShellExecute = false; 
           proc.StartInfo.RedirectStandardError = true;  
           proc.StartInfo.RedirectStandardInput = true;  
           proc.StartInfo.RedirectStandardOutput = true;
           try
           {
               proc.Start();
               if (cmd.Length != 0)
               {
                   proc.StandardInput.WriteLine(cmd);
               }
               proc.Close();  
           }
           catch (Exception  )
           {
               throw;
           }
        
       }
    }   
    }
 


[解决办法]
换成notepad.exe 试试,如果可以,证明组件不是注册表允许的。

如果不可以,证明web用户压根不具有执行cmd 命令的权限。

热点排行