views:

32

answers:

0

Setup: I have the user object in hand, via win32com.client.Dispatch('ADsNameSpaces'), in a standard Windows environment, using ActiveState Python of the 2.6 flavor. Apparently, Get() and Put()/SetInfo() methods are the appropriate ways to read from and write to properties of the object. My approach has been to simply adapt examples from the Active Directory Cookbook to Python. I can set other properties (password, sn, givenName, etc) of the user object and otherwise activate the account, add it to groups, but setting the expiration date seems to be problematic.

In VBScript (I know, I know, that's what's in the book) you can do a:

objUser.AccountExpirationDate = '12/31/2010'
objUser.SetInfo

I also know that there's a separate accountExpires property. I can perform a times = objUser.Get('accountExpires') and receive an object with a .HighPart and a .LowPart, as I know the information is internally stored, so I feel I am on the right track.

Additionally, I have written functions which convert human readable dates to Unix Epoch time, and from there to the 64-bit Microsoft time format (100 nanosecond intervals since January 1, 1601; stored as a 32-bit HighPart and a 32-bit LowPart), should these be required.


Failed attempts:

1)

objUser.AcccountExpirationDate = '03/20/2010'
>>AttributeError: Property '<unknown>.AcccountExpirationDate' can not be set.

2)

objUser.Put('AccountExpirationDate', '03/20/2010')
>>  File "<COMObject <unknown>>", line 2, in SetInfo
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Active Directory', u'The specified directory service attribute or value does not exist.\r\n', None, 0, -2147016694), None)

3)

times = objUser.Get('accountExpires')
print 'highpart: ' + str(times.HighPart)
# "highpart" variable computed elsewhere
times.Put('HighPart', highpart)
>>AttributeError: <unknown>.Put

Failed inspection attempts for the derived "times" object and the parts within it (HighPart, LowPart):

1) dir() has not been helpful with my attempts to inspect the object, putting forth nothing that looks unusual.

2) The "Guide to Python introspection" article (http://www.ibm.com/developerworks/library/l-pyint.html), which interesting, has not provided any more insight.

3) I have a great deal of bewildering, but highly generic-looking, output from the inspect module; nothing says "Hi, put a 32-bit integer in me!"

Where do I go from here?