在C#中使windows目录受密码保护?
我想对一个目录以及所有子文件夹和文件进行密码保护,以便任何人都无法通过 Windows 资源管理器访问,并且当他输入正确的密码时,可以通过 C# 代码撤消密码保护。
建议我如何执行此操作并提供示例代码(如果可能)。
提前致谢。
I want to make a directory and all subfolders and files password protected so that no one can access through the Windows Explorer and when he entered the correct password undo the password protected through C# code.
suggest me How to do this and provide sample code if possible.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用受密码保护的 zip 文件。
如果您想询问密码并在 C# 中解压它,您可以使用流行的 C# 库:
http:// /www.icsharpcode.net/opensource/sharpziplib/
I would use a password protected zip file.
If you wish to ask for a password and unzip it in C# you could use the popular C# library:
http://www.icsharpcode.net/opensource/sharpziplib/
这个问题似乎已经被问过。
我建议要么使用加密的 zip,如德里克回答,或者如果您只是想阻止用户访问文件而不实际加密或编辑这些文件,请尝试 在文件名中使用 CLSID 从 Windows 资源管理器中隐藏文件夹。
如果您想使用该方法,只需在文件夹中添加一个包含密码的文本文件即可。当您想要“解锁”它时,只需要求输入密码,对照文件夹中的文本文件进行检查,删除文本文件并从文件夹名称中删除 CLSID。请注意,它不会以任何方式保护实际文件本身,只是阻止用户以传统方式访问它,这似乎就是您的问题所要求的。
This question appears to have already been asked.
I'd suggest either using encrypted zips as Derek answered, or if you just want to stop the users from accessing the files without actually encrypting or editing those files, try using CLSIDs in file names to hide folders from windows explorer.
If you'd like to use that method, just add a text file inside the folder with the password in it. When you want to 'unlock' it, just ask for a password, check it against the text file in the folder, delete the textfile and remove the CLSID from the folder's name. Note that it doesn't protect the actual files themselves in any way, just prevents users from accessing it in the conventional ways, which seems to be what your question is asking.
这个链接对我解决这个问题有很大帮助。
http://www.codeproject.com /Articles/20880/Folder-protection-for-windows-using-C-Concepts-on
现在我正在调用批处理文件来重命名文件夹并撤消重命名 文件夹。
这也解释了如何添加到目录的右键单击操作并通过运行命令运行。
这里的缺点是CLSID在XP机器上不支持。但在部署配置中它会起作用。
也许这会有所帮助。
正如我提到的,我不想重命名该文件夹。我现在正在检查带有或不带有 CLSID 的路径,以访问其中的文件。
This Link help me a lot in solving this problem.
http://www.codeproject.com/Articles/20880/Folder-protection-for-windows-using-C-Concepts-on
Now I am calling a batch file to rename the folder and undo renaming the folder.
This also explains about how to add to the Right click action of the dir and run through the run command.
Disadvantage here is the CLSID in the XP machine does't support. But in the deployment configuration it will work.
May be this will help.
As I mentioned I don't Want to rename the folder. I am now checking the path with or without the CLSID for accessing the files in it.