服务器之家

服务器之家 > 正文

VBSCript之GenerateSDDL函数(权限设置)

时间:2020-08-10 11:00     来源/作者:enun
复制代码 代码如下:


Function GenerateSDDL(AccountName, AccessFlag, AccessType, AccessMask)
 Dim Accounts, ObjWMI, ObjSID, ObjTru, ObjACE
 Const SET_DACL_PRESENT = &H8004

 Set ObjWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate, (Security)}!\\.\root\cimv2")

 

 Set Accounts = ObjWMI.ExecQuery("SELECT * FROM Win32_Account WHERE Name='" & AccountName & "'")
 For Each Account In Accounts
  StrSID = Account.SID
 Next
 Set ObjSID = ObjWMI.Get("Win32_SID.SID='"& StrSID &"'")

 Set ObjTru = ObjWMI.Get("Win32_Trustee").SpawnInstance_()
 ObjTru.Domain  = ObjSID.ReferencedDomainName
 ObjTru.Name   = ObjSID.AccountName
 ObjTru.SID   = ObjSID.BinaryRepresentation
 ObjTru.SidLength = ObjSID.SidLength
 ObjTru.SIDString = ObjSID.Sid

 Set ObjACE = ObjWMI.Get("Win32_ACE").SpawnInstance_()
 ObjACE.Trustee   = ObjTru
 ObjACE.AceType   = AccessType
 ObjACE.AccessMask  = AccessMask
 ObjACE.AceFlags  = AccessFlag

 Set GenerateSDDL = ObjWMI.Get("Win32_SecurityDescriptor").SpawnInstance_()
 GenerateSDDL.Owner   = ObjTru
 GenerateSDDL.DACL   = Array(ObjACE)
 GenerateSDDL.ControlFlags = SET_DACL_PRESENT
End Function

 

例子:

 

复制代码 代码如下:

strPath = "d:\\1.txt"
Set ObjWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate, (Security)}!\\.\root\cimv2")
Set ObjSec = ObjWMI.Get("Win32_LogicalFileSecuritySetting.Path='" & strPath & "'")
ObjSec.SetSecurityDescriptor(GenerateSDDL("everyone", &H0, &H1, &H100E0))

 

文章来源: http://www.enun.net/?p=1255

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意 2019-07-07
返回顶部