当前位置: 首页>>代码示例>>Python>>正文


Python Dispatch.AccessMask方法代码示例

本文整理汇总了Python中win32com.client.Dispatch.AccessMask方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatch.AccessMask方法的具体用法?Python Dispatch.AccessMask怎么用?Python Dispatch.AccessMask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32com.client.Dispatch的用法示例。


在下文中一共展示了Dispatch.AccessMask方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AllowAccessToScpProperties

# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import AccessMask [as 别名]
def AllowAccessToScpProperties(
    accountSAM, #Service account to allow access.
    scpObject, # The IADs SCP object.
    schemaIDGUIDs = # Attributes to allow write-access to.
        ("{28630eb8-41d5-11d1-a9c1-0000f80367c1}", # serviceDNSName
         "{b7b1311c-b82e-11d0-afee-0000f80367c1}",  # serviceBindingInformation
        )
    ):  
    
    # If no service account is specified, service runs under LocalSystem.
    # So allow access to the computer account of the service's host.
    if accountSAM:
        trustee = accountSAM
    else:
        # Get the SAM account name of the computer object for the server.
        trustee = win32api.GetComputerObjectName(win32con.NameSamCompatible)
    
    # Get the nTSecurityDescriptor attribute
    attribute = "nTSecurityDescriptor"
    sd = getattr(scpObject, attribute)
    acl = sd.DiscretionaryAcl

    for sguid in schemaIDGUIDs:
        ace = Dispatch(adsi.CLSID_AccessControlEntry)

        # Set the properties of the ACE.
        # Allow read and write access to the property.
        ace.AccessMask = ADS_RIGHT_DS_READ_PROP | ADS_RIGHT_DS_WRITE_PROP

        # Set the trustee, which is either the service account or the 
        # host computer account.
        ace.Trustee = trustee

        # Set the ACE type.
        ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT

        # Set AceFlags to zero because ACE is not inheritable.
        ace.AceFlags = 0

        # Set Flags to indicate an ACE that protects a specified object.
        ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT

        # Set ObjectType to the schemaIDGUID of the attribute.
        ace.ObjectType = sguid

        # Add the ACEs to the DACL.
        acl.AddAce(ace)

    # Write the modified DACL back to the security descriptor.
    sd.DiscretionaryAcl = acl
    # Write the ntSecurityDescriptor property to the property cache.
    setattr(scpObject, attribute, sd)
    # SetInfo updates the SCP object in the directory.
    scpObject.SetInfo()
    logger.info("Set security on object for account '%s'" % (trustee,))
开发者ID:8dspaces,项目名称:Pywin32,代码行数:57,代码来源:scp.py


注:本文中的win32com.client.Dispatch.AccessMask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。