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

来源:互联网 发布:php基础面试题 编辑:程序博客网 时间:2024/05/16 08:58
       #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();//其实部署版本没有多大用处。
原创粉丝点击