Beispiel #1
0
def LocalGroup(uname=None):
    "Creates a local group, adds some members, deletes them, then removes the group"
    level = 3
    if uname is None: uname = win32api.GetUserName()
    if uname.find("\\") < 0:
        uname = win32api.GetDomainName() + "\\" + uname
    group = 'python_test_group'
    # delete the group if it already exists
    try:
        win32net.NetLocalGroupDel(server, group)
        print "WARNING: existing local group '%s' has been deleted."
    except win32net.error:
        pass
    group_data = {'name': group}
    win32net.NetLocalGroupAdd(server, 1, group_data)
    try:
        u = {'domainandname': uname}
        win32net.NetLocalGroupAddMembers(server, group, level, [u])
        mem, tot, res = win32net.NetLocalGroupGetMembers(server, group, level)
        print "members are", mem
        if mem[0]['domainandname'] != uname:
            print "ERROR: LocalGroup just added %s, but members are %r" % (
                uname, mem)
        # Convert the list of dicts to a list of strings.
        win32net.NetLocalGroupDelMembers(server, group,
                                         [m['domainandname'] for m in mem])
    finally:
        win32net.NetLocalGroupDel(server, group)
    print "Created a local group, added and removed members, then deleted the group"
def create_group(group):
    group_info = dict(name=group)
    try:
        win32net.NetLocalGroupDel(None, group)
    except win32net.error as error:
        number, context, message = error.args
        if number != 2220:
            raise
    win32net.NetLocalGroupAdd(None, 0, group_info)
Beispiel #3
0
    def groupCreate(name_):
        try:
            data = {}
            data['name'] = name_
            data['comment'] = ''

            win32net.NetLocalGroupAdd(None, 1, data)
        except win32net.error, e:
            Logger.error("SessionManagement createGroupOVD: '%s'" % (str(e)))
            return False
Beispiel #4
0
    def groupCreate(name_):
        try:
            data = {}
            data['name'] = name_
            data['comment'] = ''

            win32net.NetLocalGroupAdd(None, 1, data)
        except win32net.error:
            Logger.exception("SessionManagement createGroupOVD")
            return False

        return True
Beispiel #5
0
    win32net.NetUserDel (None, user)
  except win32net.error, (number, context, message):
    if number <> 2221:
      raise
  win32net.NetUserAdd (None, 1, user_info)

def create_group (group):
  group_info = dict (
    name = group
  )
  try:
    win32net.NetLocalGroupDel (None, group)
  except win32net.error, (number, context, message):
    if number <> 2220:
      raise
  win32net.NetLocalGroupAdd (None, 0, group_info)

def add_user_to_group (user, group):
  user_group_info = dict (
    domainandname = user
  )
  win32net.NetLocalGroupAddMembers (None, group, 3, [user_group_info])

def delete_user (user):
  try:
    win32net.NetUserDel (None, user)
  except win32net.error, (errno, errctx, errmsg):
    if errno != 2221: raise

def delete_group (group):
  try: