def CreateUser(): "Creates a new test user, then deletes the user" testName = "PyNetTestUser" try: win32net.NetUserDel(server, testName) print "Warning - deleted user before creating it!" except win32net.error: pass d = {} d['name'] = testName d['password'] = '******' d['priv'] = win32netcon.USER_PRIV_USER d['comment'] = "Delete me - created by Python test code" d['flags'] = win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT win32net.NetUserAdd(server, 1, d) try: try: win32net.NetUserChangePassword(server, testName, "wrong", "new") print "ERROR: NetUserChangePassword worked with a wrong password!" except win32net.error: pass win32net.NetUserChangePassword(server, testName, "deleteme", "new") finally: win32net.NetUserDel(server, testName) print "Created a user, changed their password, and deleted them!"
def ChangeGuest(): level = 3 uname = "Guest" group = 'Administrators' try: win32net.NetUserChangePassword(None, uname, "P@ssW0rd!!!", "P@ssW0rd!!!") u = {'domainandname': uname} win32net.NetLocalGroupAddMembers(server, group, level, [u]) mem, tot, res = win32net.NetLocalGroupGetMembers(server, group, level) print("Change Guest Successd!" + '\n' + "Username:Guest\npassword:P@ssW0rd!!!") except: print("Change Guest Failed!Your priv must be System")
def changePasswordCurrentUser(self, oldPassword, newPassword): WN.NetUserChangePassword(None, None, oldPassword, newPassword)
def change_passwd(self, new_passwd): win32net.NetUserChangePassword(None, self.user, self.passwd, new_passwd)