views:

632

answers:

3

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?

A: 

That change would require administrator permissions, which may (or may not) cause issues inside of PyWin32. I don't see any straight-forward way of making this change from a Python script, but I'm sure this can be automated using a different method.

This MSFN thread seems to have info that will help you, or at least a start:

http://www.msfn.org/board/Password-Expires-Chang-t115757.html

jcoon
A: 

You might need admin priviliges to do that, so look into elevating the current process or launch a new process with more priviliges. (I.e. something like vista's UAC but on XP.)

Can't help with details though. :-/

Marcus Lindblom
+1  A: 

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 for bit values.

David Leonard