c#.net 更改文件夹权限

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
/// <summary>
/// Command 的摘要说明
/// </summary>
namespace Command
{
    public class Command
    {
        //   <summary>  
        //   运行指定命令行  
        //   </summary>  
        //   <param   name="cmd">命令</param>  
        //    <param   name="arg">命令行参数</param>  
        // <param   name="comfirm">写入命令行的确认信息</param>  
        //   <returns></returns>  
        public static string Execute(string cmd, string arg, string comfirm)
        {
            Process p = new Process();
            p.StartInfo.FileName = cmd;
            p.StartInfo.Arguments = arg;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            if (comfirm != null)
                p.StandardInput.WriteLine(comfirm);
            string msg = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();

            return msg;
        }
    }
}

调用方法 Command.Command.Execute("cacls", filename + " /t /g everyone:f","Y");  

注意 cacls中的文件名不允许有空格

结局方法:   只需用“”将路径引起来

如:string filename = '"'+pathStr+'"';即可

你可能感兴趣的:(c#.net 更改文件夹权限)