C#应用程序的UAC控制,提升应用程序权限。获得版本号码

       #region 
        /// <summary>
        /// 设置文件的访问权限
        /// </summary>
        /// <param name="filePath"> 路径</param>
        /// <param name="username"> 用户名</param>
        /// SetAccount(@"C:\eee.txt", "BATCH");
        public static void SetAccount(string filePath, string username)
        {

            FileInfo fileInfo = new FileInfo(filePath);

            FileSecurity fileSecurity = fileInfo.GetAccessControl();

            fileSecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, AccessControlType.Allow));     //以完全控制为例

            fileInfo.SetAccessControl(fileSecurity);

        }
       /// <summary>
       /// 设置路径的访问权限
       /// </summary>
       /// <param name="FolderPath">路径</param>
       /// <param name="UserName">用户名</param>
       /// <param name="Rights">权限</param>
       /// <param name="AllowOrDeny">可访问</param>
       /// <returns></returns>
        /// 调用方式SetFolderACL("C:\\test", "BATCH", FileSystemRights.FullControl, AccessControlType.Allow);    
        public static bool SetFolderACL(String FolderPath, String UserName, FileSystemRights Rights, AccessControlType AllowOrDeny)
        {

            InheritanceFlags inherits = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;

            return SetFolderACL(FolderPath, UserName, Rights, AllowOrDeny, inherits, PropagationFlags.None, AccessControlModification.Add);

        }

        public static bool SetFolderACL(String FolderPath, String UserName, FileSystemRights Rights, AccessControlType AllowOrDeny, InheritanceFlags Inherits, PropagationFlags PropagateToChildren, AccessControlModification AddResetOrRemove)
        {

            bool ret;

            DirectoryInfo folder = new DirectoryInfo(FolderPath);

            DirectorySecurity dSecurity = folder.GetAccessControl(AccessControlSections.All);

            FileSystemAccessRule accRule = new FileSystemAccessRule(UserName, Rights, Inherits, PropagateToChildren, AllowOrDeny); 
            dSecurity.ModifyAccessRule(AddResetOrRemove, accRule, out ret);
            folder.SetAccessControl(dSecurity);

            return ret;

        }
        #endregion

using System.Deployment.Application;

Content.Text = "程序集版本:" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() +"\n";
Content.Text += "文件版本:" + Application.ProductVersion.ToString() +"\n";
Content.Text += "部署版本:" + ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();//其实部署版本没有多大用处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值