问题
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