[python-win32] Creating users with ADSI
d.w. harks
dave at psys.org
Fri Oct 31 20:30:55 EST 2003
With carefully-arranged electrons, Pierre Hj?lm wrote:
> Why does the code below give this error message?:
>
> Traceback (most recent call last):
> File "usertest2.py", line 12, in ?
> aduser.Setinfo()
> File "<COMObject <unknown>>", line 2, in Setinfo
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147019886), None)
>
>
> # code
> from win32com.client import Dispatch
>
> adsi=Dispatch("ADsNamespaces")
> ou=adsi.GetObject("","LDAP://ou=Employees,dc=test,dc=local")
> # above line changed to protect the innocent ;)
>
> aduser=ou.Create("User","cn=test")
>
> aduser.Put("sAMAccountName","test")
> aduser.Put("givenName","test")
> aduser.Put("sn","test")
> aduser.Put("userPrincipalName","test")
> aduser.Setinfo()
>
try:
aduser=ou.Create("User","cn=test")
aduser.Put("sAMAccountName", "blah")
aduser.Setinfo()
aduser.Put("givenName","test)
...
aduser.Setinfo()
As to why there would need to be a separate setinfo() call to set the
samaccountname, I'm not entirely sure. I think it has to do with some extra
data sitting in the property cache, causing setinfo to get confused...
dave
--
David W. Harks <dave at psys.org> http://dwblog.psys.org
More information about the Python-win32
mailing list