前言:
作为一个用惯了Linux类系统的人,突然更换成了需要操作的windows系统,而且要对windows系统做操作一些获取类的操作,对我来说就感觉十分困难;获取属主属组在Linux内一行命令就可以解决的事情放在windows就让我变得毫无头绪。
这次分享我将已经踩完坑的代码发布出来,并且代码整量就是来做获取文件owner、对文件赋权、和修改owner的
需要用到的模块
win32security
win32api
①、获取一个文件的owner,即所有者
new_file = path+file
def get_file_owner(new_file):
sd = win32security.GetFileSecurity(
new_file, win32security.OWNER_SECURITY_INFORMATION
)
owner_sid = sd.GetSecurityDescriptorOwner()
name, domain, account_type = win32security.LookupAccountSid(None, owner_sid)
if dimain == win32api.GetComputerName():
domain == "."
if name == "Administrators":
__local_administrators = "%s\\Administrators" % win32a