在受限用户帐户 XP 中运行时,C# 应用程序无法读取/写入管理员创建的文件
我有一个可供所有用户(管理员或受限用户)在 .NET(特别是 C#)中使用的应用程序。
当应用程序首次启动时 - 它会在 C:\Documents and Settings\All Users\Documents\ 中创建一些后续启动所需的文件。
如果 XP 中的受限用户是第一个启动该应用程序的用户,那么它会正常创建文件,并且受限用户和管理员都可以正常运行。
但是,如果管理员(或者我猜是另一个受限用户)是第一个启动该应用程序的人,那么该受限用户将无法运行该应用程序。
如果由管理员创建,则无法读取/写入的两个文件是 Log4Net 日志文件和 SQLite 数据库文件。
SQLite 数据库文件是使用直接的 .NET File.Copy(sourcepath,destinationpath) 创建的。 源路径是与应用程序一起安装的种子数据库文件 - 因此第一次运行时它会从 C:\Program Files\app install\seed.db 复制该文件
有没有办法在复制文件时设置文件的权限? 也许是 File.SetAccessControl() ? 我不清楚这是如何运作的。
另一个问题是 log4Net 滚动文件附加程序不会滚动旧文件并创建新文件,因为旧文件是由管理员用户在运行应用程序时创建的。
有任何想法吗? 讽刺的是,这一切在具有有限/管理员帐户的 Vista 中运行得非常好 - 这仅发生在具有管理员/有限帐户的 XP 中。
I have an application that is useable by all users (admin or limited) in .NET (C# specifically).
When the application first launches - it creates a few files that it needs in the C:\Documents and Settings\All Users\Documents\ for all subsequent launches.
If the limited user in XP is the FIRST user to launch the application it creates the files fine and both the limited user and administrators can run fine.
However if the Administrator (or I am guessing a different limited user) is the first to launch the application then the limited user is NOT able to run the application.
The two files that it is NOT able to read/write to if created by an Administrator is a Log4Net log file and a SQLite db file.
The SQLite database file is being created with a straitforward .NET File.Copy(sourcepath, destinationpath). The sourcepath is a seed database file installed with the application - so on first run it copies that from the C:\Program Files\app install\seed.db
Is there a way to set the permissions on the file when I copy it? File.SetAccessControl() perhaps? I am not clear on how that works.
The other issue is that the log4Net rolling file appender will not roll the old file and create a new as the old file was created by the admin user when they ran the app.
Any ideas? Ironically this all works perfectly fine in Vista with limited/admin accounts - this is ONLY happening in XP with admin/limited accounts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 SetAccessControl 是可行的方法。 也许是这样的:
注意:从文件中获取现有的访问控制列表,然后将新规则添加到其中,这一点很重要。 如果您只是从头开始创建一个新的访问控制列表,那么它将完全覆盖现有的权限。
I think
SetAccessControl
is the way to go. Maybe something like this:Note: It's important that you get the existing access control list from the file and then add your new rule to that. If you just create a new access control list from scratch then it will overwrite the existing permissions completely.
是的,这是 SetAccessControl 方法,有一个很好的例子 此处
(来自 satankidneypie 的帖子)
祝你好运
Yeah, it's the SetAccessControl method all right, there is a good example here
(the post from satankidneypie)
Good luck