Get username of opened file

99封情书 提交于 2019-12-12 11:23:13

问题


Is there a way to learn the username of the user that has a file open?

I am developing a program that will be a desktop client for many users. The application will open some files and I'd like to allow many users to open the files at the same time, but only allow the first user to have write privileges. What I want is to be able to tell the other users who has write access to a file.

Is that something that can be learned by an application? (I am developing in VS 2008).


回答1:


Windows doesn't support it. But you easily add it yourself. When you gain write access to the file, write another hidden file with the user name (Environment.UserName) in the same directory (like ~originalname.username).

When you fail to gain write access, try to open that file to read the user name. Sleep for a second if that fails.



来源:https://stackoverflow.com/questions/2594241/get-username-of-opened-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!