[英]Where can i place common user data other than LOCALMACHINE -Registry without Administrative Rights
In Windows other than the registry -localmachine where can I place common user data that could be accessed by all users. 在除注册表-localmachine以外的Windows中,我可以在其中放置可由所有用户访问的公共用户数据。
i need to do this without requesting elevation of admin rights 我需要执行此操作而不要求提升管理员权限
You can store it in the Application data folder. 您可以将其存储在“应用程序数据”文件夹中。 which you can get from Envorinment:
您可以从Envorinment获得:
var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
To determine if you can access the folder without admin right, run Visual Studio, without admin rights, and see if this code executes successfully. 若要确定是否可以在没有管理员权限的情况下访问该文件夹,请在没有管理员权限的情况下运行Visual Studio,然后查看此代码是否成功执行。
class Program
{
static void Main(string[] args)
{
var folder = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
var file = Path.Combine(folder, "testfile.txt");
File.WriteAllText(file, " Test Settings");
Console.ReadLine();
}
}
No such location is available by default. 默认情况下,没有这样的位置。 Regular ( ie , non-administrative users) do not have the requisite privileges to mess with system files or files that belong to other users—that would be a security issue.
普通用户( 即非管理用户)没有必要的特权来干扰系统文件或属于其他用户的文件,这将是安全问题。 As such, they would not be able to write to a "common" directory.
因此,他们将无法写入“公用”目录。
If you need all users to be able to write to some type of common area, you need to set it up yourself. 如果您需要所有用户都可以写入某种类型的公共区域,则需要自己进行设置。 Generally, this is done by an installer application.
通常,这是由安装程序应用程序完成的。 The installer application will need to request elevation so that it has administrative privileges in order to write to restricted folders and alter security rights.
安装程序应用程序将需要请求提升权限,以便它具有管理权限,以便写入受限制的文件夹并更改安全权限。 If you're using a standard installer utility, then this is usually a built-in feature.
如果您使用的是标准安装程序实用程序,则通常是内置功能。 If you're writing your own, you arrange for it to have administrative privileges by embedding a manifest with
level
set to requireElevation
(search Stack Overflow for details). 如果你正在写你自己的,你安排它通过嵌入清单与具有管理权限
level
设置为requireElevation
(搜索栈溢出了解详细信息)。
The installer it will create a sub-directory of the common application data folder (the enumerated value Environment.SpecialFolder.CommonApplicationData
in the .NET world) for your application's use. 安装程序将创建公用应用程序数据文件夹的子目录(.NET世界中的枚举值
Environment.SpecialFolder.CommonApplicationData
)供您的应用程序使用。 By default, of course, that sub-directory will inherit the restrictions of its parent folder, so the installer will also need to explicitly set the ACL (access control list) on that sub-directory to grant all users write access. 当然,默认情况下,该子目录将继承其父文件夹的限制,因此安装程序还需要在该子目录上显式设置ACL(访问控制列表),以授予所有用户写访问权限。 This can be done in the .NET Framework using the Directory.SetAccessControl method .
这可以在.NET Framework中使用Directory.SetAccessControl方法完成 。
Then, after installation is complete, administrative privileges will not be required to run your application. 然后,安装完成后,管理权限将不再需要运行应用程序。 The application can just save into its own sub-directory of the common application data folder, which its installer has ensured that all users have read/write access to.
该应用程序可以保存到公用应用程序数据文件夹的自己的子目录中,其安装程序已确保所有用户对该文件都有读/写访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.