简体   繁体   English

是否有更好的方法使用.NET将文件移动到只读文件夹?

[英]Is there a better way to move a file to a read only folder using .NET?

I am writing a C#/WPF business application that needs to (among other things) re-organise some media files (audio, video and image files). 我正在编写一个C#/ WPF业务应用程序,该应用程序需要(除其他事项外)重新组织一些媒体文件(音频,视频和图像文件)。 The application must also run in the security context of the current user and therefore has the same access rights as them. 该应用程序还必须在当前用户的安全上下文中运行,因此具有与他们相同的访问权限。

The application is to be the one place that the media can be accessed in order to stop any unauthorised access being made to the files. 该应用程序将成为可以访问媒体以阻止对文件进行任何未经授权的访问的地方。 My initial thoughts were to organise the media in a read only folder and use a service with appropriate rights to move the files into the read only folder. 我最初的想法是将媒体组织在只读文件夹中,并使用具有适当权限的服务将文件移动到只读文件夹中。

The actual application will not have the right to move files to the read only folder because it shares the rights of the current user who must not have access rights to the folder. 实际的应用程序将无权将文件移动到只读文件夹,因为它共享当前用户的权限,该用户不能对该文件夹具有访问权限。

At first, I looked at a Windows Service, but thought that communicating with it would be too much of a pain to set up. 最初,我查看了Windows Service,但认为与它进行通信将太麻烦了。 I am therefore using a WCF service, but while the service setup works, it seems a bit of a waste to have a service that only has one method 'MoveFile'... the application (and users) can still read from the folder, just not write to it. 因此,我使用的是WCF服务,但是在服务设置正常运行的情况下,仅使用一种方法“ MoveFile”的服务似乎有点浪费……应用程序(和用户)仍然可以从文件夹中读取内容,只是不写。

Is there a better solution of moving files to a read only folder in .NET? 是否有更好的解决方案,将文件移动到.NET中的只读文件夹? Is it possible for instance, to have part of the application run as a separate user just while moving the files to the read only folder(s)? 例如,是否有可能仅在将文件移动到只读文件夹时以单独的用户身份运行应用程序的一部分?

If the current user is running the application, then the application should have the same rights. 如果当前用户正在运行该应用程序,则该应用程序应具有相同的权限。 You shouldn't need to move to a read-only folder to bypass the security. 您无需移动到只读文件夹即可绕过安全性。 You might have to catch Exceptions such as UnauthorizedAccessException if the current user doesn't have the appropriate rights. 如果当前用户没有适当的权限,则可能必须捕获诸如UnauthorizedAccessException之类的异常。

Have you tested reading directories and files with different levels of access to see if it works automatically? 您是否测试过读取具有不同访问级别的目录和文件以查看其是否自动运行?

Have you tried to impersonate the procedure to move a file from your main application ? 您是否尝试模拟从主应用程序中移动文件的过程? You can use the: WindowsIdentity.Impersonate Method 您可以使用: WindowsIdentity.Impersonate方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM