跨用户配置文件的文件权限

发布于 2024-08-22 10:12:52 字数 599 浏览 3 评论 0原文

我正在对 Windows 窗体应用程序使用 ClickOnce 部署,并且需要在跨部署和跨用户配置文件中保留的基于计算机的配置信息。因此,每用户配置没有帮助。我还希望可以使用文本编辑器轻松访问每台计算机上众所周知的位置(众所周知,即组织)的配置文件。

我遇到的问题是 ClickOnce 会覆盖每个部署上的 app.config。我知道 configsource 属性,但据我了解,目标文件必须位于应用程序的路径中 - 这意味着我无法有效控制位置。

因此,我为我想要保留的数据创建了一个类,并将其序列化/反序列化到我想要的位置。这一切都运行良好,除了如果文件不存在,我正在创建它(使用 XmlSerializer 和 TextWriter)。这里的问题是,创建应用程序时运行该应用程序的用户成为唯一可以访问该应用程序的用户。除非我手动向更广泛的 AD 组授予权限,否则后续用户没有权限。即使这样也很好,除了我不想在第一次安装每台计算机时都接触它。

那么,有没有一种好方法可以在创建文件时以编程方式设置权限,或者我应该重新考虑我的设计,因为我错过了有关内置配置功能的一些内容?

编辑:查看 Application.CommonAppDataPath,但它为应用程序的每个版本维护一个文件夹,这意味着每个新部署都将重新开始。

I am using ClickOnce deployment for a Windows Forms application and I need configuration information on a machine basis that persists across deployments and across user profiles. As such, per user configuration does not help. I would also like the configuration file to be easily accessible with a text editor in a well known location on each machine (well known, that is, by the organization).

The problem I have is that ClickOnce overwrites the app.config on each deployment. I am aware of the configsource attribute, but from what I understand, the target file has to be in the path of the application - that means that I can't control the location effectively.

So I created a class for the data I want to persist and am serializing / deserializing it to and from the location I want. This all works well, except that if the file doesn't exist I am creating it (using XmlSerializer and a TextWriter). The problem here is that the user that is running the app when it is created becomes the only user that can access it. Subsequent users do not have permission unless I grant permission to a broader AD group manually. Even this is fine except for the fact that I don't want to touch each computer the first time it is installed.

So is there a good way to programatically set permissions when the file is created or should I re-think my design because I have missed something about the built in configuration features?

EDIT: Looked in to Application.CommonAppDataPath, but it maintains a folder for each version of the application which means that each new deployment is starting over.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我老 2024-08-29 10:12:52

IIRC,您可以在单击一次应用程序中引用“所有用户应用程序数据”文件夹。

您所做的是将默认配置分发到每个应用程序的普通应用程序数据文件夹,但永远不要从该文件中读取配置信息。相反,在应用程序启动时,您会在“所有用户”应用程序数据文件夹中查找配置文件,如果找不到它,请将默认文件复制到那里。然后从该位置读取您的配置。

IIRC, You can reference the All Users Application Data folder in click once apps.

What you do is distribute your default configuration to the normal application data folder for each app, but never read config information from that file. Instead, on app startup you look in your All users application data folder for the config file, and if you don't find it copy the default file there. Then read in your config from that location.

路还长,别太狂 2024-08-29 10:12:52

基于这篇文章我这样做了:

FileSecurity fileSecurity = File.GetAccessControl(file); fileSecurity.AddAccessRule(new FileSystemAccessRule("用户", 文件系统权限.FullControl, AccessControlType.Allow)); File.SetAccessControl(文件, fileSecurity);

Based on this SO post I did this:

FileSecurity fileSecurity = File.GetAccessControl(file); fileSecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow)); File.SetAccessControl(file, fileSecurity);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文