在 C:\ProgramData\ 中写入时的权限/所有者问题 [英] Privileges/owner issue when writing in C:\ProgramData\

查看:220
本文介绍了在 C:\ProgramData\ 中写入时的权限/所有者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在 C:\Program Files (x86)\MyApp\myapp.cfg 中写入配置文件,相对于管理员权限,在 不是一个好主意>C:\Program Files (x86)\MyApp\myapp.cfg.

As pointed out in Writing config file in C:\Program Files (x86)\MyApp\myapp.cfg, vs. Administrator privilege, it is not a good idea to write a config file in C:\Program Files (x86)\MyApp\myapp.cfg.

取而代之的是,我的软件现在将其数据保存在 %ALLUSERSPROFILE% 的子目录中(例如:C:\ProgramData\MyApp\myapp.cfg 在 Win7 上)

Instead of this, my software now saves its data in a subdir of %ALLUSERSPROFILE% (ex : C:\ProgramData\MyApp\myapp.cfg on Win7)

[我在 Python 中使用 myfile = open(filename, 'a') 来做到这一点.]

[I use myfile = open(filename, 'a') in Python to do this.]

我现在遇到有关此文件的问题:

I now encounter an issue about this file :

  • 我用User A安装了软件,运行了,C:\ProgramData\MyApp\myapp.cfg文件就写好了.
  • 然后,我将用户更改为 User B,并再次运行我的软件:现在显示错误:User 2 无权在 C 中写入:\ProgramData\MyApp\myapp.cfg (权限被拒绝).
  • I installed the software with User A, and ran it, then the file C:\ProgramData\MyApp\myapp.cfg was written.
  • Then, I changed user to User B, and ran my software again : now an error is displayed : User 2 has no right to write in C:\ProgramData\MyApp\myapp.cfg (Permission denied).

为什么?%ALLUSERSPROFILE% 不是所有用户都可以写的地方吗?如何解决这个问题?

Why? Isn't %ALLUSERSPROFILE% a place that can be written by all users? How to solve this problem ?

推荐答案

否,C:\ProgramData,又名 FOLDERID_ProgramData,具有受限的安全设置.标准用户可以在那里创建文件.但默认情况下,这些文件是受保护的,因此只有创建该文件的用户才能随后修改该文件.

No, C:\ProgramData, aka FOLDERID_ProgramData, has restricted security settings. Standard users can create files there. But these files are, by default, secured so that only the user that created the file can subsequently modify the file.

推荐的解决方案是让您的安装程序为您的共享存储创建一个 C:\ProgramData 子目录.并且安装程序必须为该子目录提供一个允许的 ACL.这就是授予所有标准用户所需访问权限的原因.

The recommended solution is for your installer to create a sub directory of C:\ProgramData for your shared storage. And that sub directory must be given a permissive ACL by the installation program. That is what grants the desired access to all standard users.

我确实想知道您是否真的需要共享的可写数据.通常我希望看到共享配置是在安装时指定的并且很少由管理员修改.大多数配置数据往往是每个用户.

I do wonder whether you really need shared writeable data. Normally I'd expect to see shared configuration be something that is specified at install time and modified infrequently by administrators. Most configuration data tends to be per user.

这篇关于在 C:\ProgramData\ 中写入时的权限/所有者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆