首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Windows 7中的设置放在Okuma控件上的位置

将Windows 7中的设置放在Okuma控件上的位置
EN

Stack Overflow用户
提问于 2014-05-08 14:06:29
回答 1查看 208关注 0票数 1

我正在编写一个在Okuma控件上运行并具有应用程序设置的应用程序。因为其中一个条件是必须很容易地备份应用程序的设置,所以我将它们保存在应用程序目录中。它在控件上工作,因为应用程序转到D:但是如果有人在C驱动器上的PC上安装应用程序,应用程序无法访问它自己的应用程序目录,并且会出现错误。

条件:

  • Windows 7
  • P300控制
  • 应用程序正在安装到D-驱动器
  • 如果有人在PC上安装C驱动器,就必须工作。

是否有一个标准点来放置所有应用程序设置?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-08 14:35:03

继续将应用程序设置和其他数据保存在应用程序的安装目录中。没有必要只为“只安装PC”而更改目录位置。

文件访问问题的解决方案是在安装期间更改文件权限。

例如,this answer someone posted using WIX installer

类似的问题is answered here

您可以使用类似于此的代码在安装期间更改权限(当用户拥有管理权限时)。

代码语言:javascript
复制
using System.Security.Principal;

public static void SetPermissions()
{
String path = GetPath();
try
{
    // Create security idenifier for all users (WorldSid)  
    SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);  
    DirectoryInfo di = new DirectoryInfo(path);  
    DirectorySecurity ds = di.GetAccessControl();  

    // add a new file access rule w/ write/modify for all users to the directory security object

    ds.AddAccessRule(new FileSystemAccessRule(sid, 
        FileSystemRights.Write | FileSystemRights.Modify,
        InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,   // all sub-dirs to inherit
        PropagationFlags.None,
        AccessControlType.Allow));                                            // Turn write and modify on
    // Apply the directory security to the directory
    di.SetAccessControl(ds);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23544161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档