win32net.NetUserAdd

Here are the examples of the python api win32net.NetUserAdd taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: cloudbase-init
Source File: windows.py
View license
    def create_user(self, username, password, password_expires=False):
        user_info = {
            "name": username,
            "password": password,
            "priv": win32netcon.USER_PRIV_USER,
            "flags": win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT,
        }

        if not password_expires:
            user_info["flags"] |= win32netcon.UF_DONT_EXPIRE_PASSWD

        try:
            win32net.NetUserAdd(None, 1, user_info)
        except win32net.error as ex:
            raise exception.CloudbaseInitException(
                "Create user failed: %s" % ex.args[2])

Example 2

Project: imagefactory
Source File: consumer-service.py
View license
    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_,''))

        
        # Create an Administrator account to be impersonated and used for the process
        def create_user():
            params={}
            params['name']= 'RHAdmin'
            digits = "".join( [random.choice(string.digits) for i in range(10)] )
            chars_lower = ''.join( [random.choice(string.ascii_lowercase) for i in range(10)] )
            chars_upper = ''.join( [random.choice(string.ascii_uppercase) for i in range(10)] ) 
            params['password']= digits+chars_lower+chars_upper
            params['password'] = ''.join([str(w) for w in random.sample(params['password'], len(params['password']))])
            params['flags']= win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT
            params['priv'] = win32netcon.USER_PRIV_USER

            user = win32net.NetUserAdd(None, 1, params)
            domain = socket.gethostname()
            data = [ {'domainandname' : domain+'\\RHAdmin'} ]
            win32net.NetLocalGroupAddMembers(None, 'Administrators', 3, data)
            return params['password']
        
        try:
            win32net.NetUserDel(None, 'RHAdmin')
            Password = create_user()
        except:
            Password = create_user()
        

        token = win32security.LogonUser('RHAdmin', None, Password, \
        	       win32con.LOGON32_LOGON_INTERACTIVE,
                    win32con.LOGON32_PROVIDER_DEFAULT)
        win32security.ImpersonateLoggedOnUser(token)
        self.main(token)

Example 3

Project: winsys
Source File: accounts.py
View license
    @classmethod
    def create(cls, username, password, system=None):
        """Create a new user with `username` and `password`. Return
        a :class:`User` for the new user.

        :param username: username of the new user. Must not already exist on `system`
        :param password: password for the new user. Must meet security policy on `system`
        :param system: optional system name
        :returns: a :class:`User` for `username`
        """
        user_info = dict(
            name = username,
            password = password,
            priv = USER_PRIV.USER,
            home_dir = None,
            comment = None,
            flags = UF.SCRIPT,
            script_path = None
        )
        wrapped(win32net.NetUserAdd, system, 1, user_info)
        return cls.from_string(username, system)

Example 4

Project: WAPT
Source File: accounts.py
View license
    @classmethod
    def create(cls, username, password, system=None):
        """Create a new user with `username` and `password`. Return
        a :class:`User` for the new user.

        :param username: username of the new user. Must not already exist on `system`
        :param password: password for the new user. Must meet security policy on `system`
        :param system: optional system name
        :returns: a :class:`User` for `username`
        """
        user_info = dict(
            name = username,
            password = password,
            priv = USER_PRIV.USER,
            home_dir = None,
            comment = None,
            flags = UF.SCRIPT,
            script_path = None
        )
        wrapped(win32net.NetUserAdd, system, 1, user_info)
        return cls.from_string(username, system)

Example 5

Project: WAPT
Source File: BatchUserCreate.py
View license
def CreateUserAndShare(userName, fullName):
    homeDir = "%s\\%s" % (serverName, userName)
    # Create user data in information level 3 (PyUSER_INFO_3) format.
    userData = {}
    userData['name'] = userName
    userData['full_name'] = fullName
    userData['password'] = userName
    userData['flags'] = win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT
    userData['priv'] = win32netcon.USER_PRIV_USER
    userData['home_dir'] = homeDir
    userData['home_dir_drive'] = "P:"
    userData['primary_group_id'] = ntsecuritycon.DOMAIN_GROUP_RID_USERS
    userData['password_expired'] = 1 # User must change password next logon.

    # Create the user
    win32net.NetUserAdd(serverName, 3, userData)

    # Create the new directory, then the share
    dirName = os.path.join(homeRoot, userName)
    os.mkdir(dirName)
    shareData = {}
    shareData['netname'] = userName
    shareData['type'] = win32netcon.STYPE_DISKTREE
    shareData['path'] = dirName
    shareData['max_uses'] = -1
    # The security setting for the share.
    sd = CreateUserSecurityDescriptor(userName)
    shareData['security_descriptor'] = sd
    # And finally create it.
    win32net.NetShareAdd(serverName, 502, shareData)