Max*_*xKu 4 c python windows file owner
我有一个问题 - 在打开文件时的窗口中显示上次修改文件的人的姓名。如果您右键单击文件并选择“属性”和“详细信息”选项卡,则可以使用此信息...我看到所有者行和名称,但我不知道如何从我的脚本中获取此信息。
让我们看看文件上的属性:
\\server\project\sequences\ttt_sRnd.v016.mb
Run Code Online (Sandbox Code Playgroud)
我使用 Python2.7,但我没有找到如何获取数据的解决方案......在 linux 中它起作用了。但不是在窗口中。我试图控制台实用程序窗口。
dir /Q - 它适用于本地文件
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
Run Code Online (Sandbox Code Playgroud)
但在服务器上文件时不起作用:
\\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
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为在资源管理器中我可以看到数据并且它们可用
好吧,尝试另一个实用程序 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.
Run Code Online (Sandbox Code Playgroud)
我尝试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.
Run Code Online (Sandbox Code Playgroud)
它在 Windows 中可能还有其他实用程序吗?我什至准备好自己编写这样的工具并从 python 中调用它。但我不知道如何获得这些信息?告诉我如何在任何编程语言中崩溃问题?我相信在 C/?++ 或 C# 代码中是 5 行输出到控制台的问题......如果是这样 - 什么会很乐意提供帮助,然后我将从 python 中创建这个实用程序
小智 5
python 2.7
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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2618 次 |
| 最近记录: |