How can I modify password expiration in Windows using Python?
Question: How can I modify the password expiration to "never" on Windows XP for a local
user with Python? I have the PyWIN and WMI modules on board but have no
solution. I managed to query the current settings via WMI(based on
Win32_UserAccount class), but how can modify it?


Answer: If you are running your python script with ActvePython against Active
Directory, then you can use something like this:

    
    
    import win32com.client
    ads = win32com.client.Dispatch('ADsNameSpaces')
    user = ads.getObject("", "WinNT://DOMAIN/username,user")
    user.Getinfo()
    user.Put('userAccountControl', 65536 | user.Get('userAccountControl'))
    user.Setinfo()
    

But if your python is running under unix, you need two things to talk to
Active Directory: Kerberos and LDAP. Once you have a SASL(GSSAPI(KRB5))
authenticated LDAP connection to your Active Directory server, then you access
the target user's "userAccountControl" attribute.

userAccountControl is an integer attribute, treated as a bit field, on which
you must set the DONT EXPIRE PASSWORD bit. See [this KB
article](http://support.microsoft.com/kb/305144) for bit values.

