我在c#中调用cmd.exe执行ping命令正常,但是我执行set 命令和ren 命令都不能正常执行。
是不是权限的问题?但是我把要批量改名的文件夹赋予了asp.net和everyone的写权限还是不能执行ren的批量修改和set系统变量!!!
请高手指点。

解决方案 »

  1.   

    ren命令的格式是:ren 源文件名 目的文件名。格式正确?提示什么问题?
      

  2.   


    private static string runcmd(string command)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";           
                p.StartInfo.Arguments = "/c " + command;    
                p.StartInfo.UseShellExecute = false;        
                p.StartInfo.RedirectStandardInput = true;   
                p.StartInfo.RedirectStandardOutput = true;  
                p.StartInfo.RedirectStandardError = true;   
                p.StartInfo.CreateNoWindow = true;          
                p.Start();   
                return p.StandardOutput.ReadToEnd();        
            }调用runcmd(@"ren C:\1.txt 1.xml");
      

  3.   

    ren等命令不能直接执行,它们是cmd.exe的参数
    ping直接就是一个ping.exe
    在ren前加上cmd.exe /c
    就可以了
      

  4.   


    这个应该是正解,ren是内部命令,ping是外部命令,楼主可以试试xcopy能不能执行,再试试dir命令,如果xcopy能执行而dir不行那就是这个问题了。