获取打开的文件的用户名 [英] Get username of opened file

查看:124
本文介绍了获取打开的文件的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有方法可以学习打开文件的用户的用户名?

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.

这是应用程序可以学习的东西吗? (我在VS 2008中开发)。

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

推荐答案

Windows不支持。但你可以很容易地添加它自己。当您获得文件的写访问权限时,在同一目录(例如〜originalname.username)中写入另一个具有用户名(Environment.UserName)的隐藏文件。

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.

这篇关于获取打开的文件的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆