本文介绍了C#应用程序无法读取/在受限用户帐户XP上运行时,写入由管理员创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它是在.NET(C#专)的所有用户可用(admin或限制)

I have an application that is useable by all users (admin or limited) in .NET (C# specifically).

当应用程序首次启动 - 它会创建一个它在C需要几个文件:\Documents和Settings\All Users\Documents\所有后续启动

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.

如果在XP中的受限用户第一个用户启动应用程序它创建的文件很好,无论是有限的用户和管理员可以运行得很好。

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.

这两个文件,这是不能够读/写,如果由管理员是一个log4net的日志文件,一个SQLite数据库文件。

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.

SQLite数据库文件正在被使用straitforward .NET File.Copy(源路径,的DestinationPath)创建的。源路径是安装了应用程序的种子数据库文件 - 所以在第一次运行它复制从C:\Program Files\app install\seed.db

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

有没有一种方法来设置文件的权限,当我将它复制? File.SetAccessControl()吧?我不是如何工作的明确。

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.

另一个问题是,log4net的滚动文件Appender将不会推出旧文件并创建一个新的旧文件被创建由当他们运行的应用程序的管理员用户。

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.

任何想法?讽刺的是这一切工作完全正常在Vista中有限的/管理员帐户 - 这是在XP中只发生与管理/受限帐户

Any ideas? Ironically this all works perfectly fine in Vista with limited/admin accounts - this is ONLY happening in XP with admin/limited accounts.

推荐答案

是啊,这是SetAccessControl方法没事,有一个很好的例子的
(从satankidneypie后)

Yeah, it's the SetAccessControl method all right, there is a good example here (the post from satankidneypie)

好运气

这篇关于C#应用程序无法读取/在受限用户帐户XP上运行时,写入由管理员创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:03