如何在Windows 7中获取文件的所有者? [英] How to get the owner of the file in the windows 7?

查看:437
本文介绍了如何在Windows 7中获取文件的所有者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题-打开文件时,在窗口中显示了上次修改文件的人的名字.如果右键单击该文件,然后选择属性"和详细信息"选项卡,则此信息可用.我看到所有者行和名称,但我不知道如何从脚本中获取此信息.

I have a problem - in the window when the file is opened to show the name of the one who last modified the file. This information is available if you right-click on the file and select Properties and tab Details... i see Owner line and name but i dont know how to get this from my script.

让我们查看文件中的属性:

lets see properties on file:

\\server\project\sequences\ttt_sRnd.v016.mb

我使用Python2.7,但没有找到如何获取数据的解决方案……在linux中有效.但不在Windows中. 我试图控制台实用程序窗口.

I use Python2.7 and and I do not find the solution how to get the data... in linux its worked. but not in windows. I tried to console utilities windows.

dir/Q-它适用于本地文件

dir /Q - its worked on local files

C:\temp>dir /Q file.ext
11/06/2004  15:33           290,304 COMP\user       file.ext
               1 File(s)        290,304 bytes
               0 Dir(s)  316,720,226,304 bytes free

但是在服务器上的文件不起作用时

but don't worked when file on server:

\\server\project\sequences\>dir /Q file.ext
21/12/2016  16:00            66,372 ...                    file.ext
               1 File(s)         66,372 bytes
               0 Dir(s)  52,561,190,912 bytes free

这很奇怪,因为在资源管理器中我可以看到数据并且它们可用

it's strange, because in the explorer I can see the data and they are available

好吧,尝试另一个实用程序subinacl.exe

well, try another utility subinacl.exe

相同-在本地文件上使用,而在服务器上不使用:

its the same - worked on local files and not worked with file on server:

C:\temp>subinacl.exe /file file.ext /display=owner
/owner             =comp\user

C:\temp>subinacl.exe /file \\server\project\sequences\file.ext  /display=owner
\\server\project\sequences\file.ext - CreateFile Error : 1314 A required privilege is not held by the client.

我尝试takeown都一样-仅适用于本地文件:

i try takeown and all the same - work only on local files:

C:\temp>takeown /F file.ext
SUCCESS: The file (or folder): "C:\temp\file.ext" now owned by user "COMP\user".

\\server\project\sequences\>takeown /F file.ext
ERROR: Access is denied.

在Windows中可能还有其他实用程序吗? 我什至准备自己编写这样的工具,并从python调用它.但我不知道如何获取这些信息?告诉我如何以任何编程语言崩溃的问题?我相信,在C/С++或C#代码中,仅需5行代码即可输出到控制台……如果这样的话-乐于助人的是什么,然后我将从python中创建该实用程序

It may have something else utility in windows? I am ready even to write such a tool myself and call it from python. but I have no idea how to get this information? tell me how to crash problem in any programming language? I believe that in C/С++ or C# code is a matter of the 5-lines with the output to the console ... if so - what will be glad to help, and then I will cause this utility from python

推荐答案

python 2.7

尝试使用win32security库中的功能(GetFileSecurity和LookupAccountSid),您将获得有关所有者的信息

try to use the functions (GetFileSecurity and LookupAccountSid) from the win32security library and you will obtain information about owner

import win32security

def GetOwner(filename):
    f = win32security.GetFileSecurity(filename, win32security.OWNER_SECURITY_INFORMATION)
    (username, domain, sid_name_use) =  win32security.LookupAccountSid(None, f.GetSecurityDescriptorOwner())
    return username

print GetOwner(r"\\some_shared_location\somefile.txt")

这篇关于如何在Windows 7中获取文件的所有者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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