在Okuma控件上将Windows 7中的设置放在何处

时间:2014-05-08 14:06:29

标签: okuma

我正在编写将在Okuma控件上运行并具有应用程序设置的应用程序。 由于其中一个条件是必须轻松备份应用程序的设置,因此我将它们保存在应用程序目录中。它适用于控件,因为应用程序转到D:但是如果有人在C盘上的PC上安装应用程序,则应用程序无法访问它自己的应用程序目录并且它会出错。

条件:

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

是否有标准位置来放置所有应用程序设置?

1 个答案:

答案 0 :(得分:2)

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

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

例如,this answer someone posted using WIX installer

类似问题is answered here

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

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);
    }
}
相关问题