如何在Windows7中获取文件的所有者?

2024-09-30 00:27:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个问题-在窗口中打开文件时显示上次修改文件的人的名字。右键单击“属性”选项卡上的“详细信息”。。。我看到了所有者的行和名称,但我不知道如何从我的脚本。在

让我们查看文件的属性:

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

enter image description here

我使用Python2.7,但我没有找到解决方案如何获得数据。。。在linux中它起作用了。但不是在窗户里。 我尝试了windows控制台。在

dir/Q-它处理本地文件

^{pr2}$

但当服务器上的文件:

\\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

这很奇怪,因为在浏览器中我可以看到数据,而且它们是可用的

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

它是相同的-处理本地文件而不是服务器上的文件:

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并且都是相同的-只在本地文件上工作:

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得到这个实用程序


Tags: 文件数据project属性serverwindowsexetemp
1条回答
网友
1楼 · 发布于 2024-09-30 00:27:25

Python2.7

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

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")

相关问题 更多 >

    热门问题