[python-win32] Active Directory Terminal Services Properties

Daniel Scoggins anywho.scoggins at gmail.com
Thu Feb 9 19:02:57 CET 2012


With a little bit of digging and scouring the MSDN site, I finally got this
to work.

<code>
        import active_directory
        import win32com
        aduser = active_directory.find_user(userid)
        adsi=win32com.client.Dispatch("ADsNameSpaces")
        ldap = adsi.getobject("","%s"%aduser)
        ldap.TerminalServicesHomeDrive = tsHomeDrive
        ldap.TerminalServicesHomeDirectory =
"%s\\%s"%(tsHomeDirectory,aduser.samaccountname)
        ldap.SetInfo()
</code>

Thanks,
Daniel Scoggins

On Wed, Feb 8, 2012 at 1:48 PM, Daniel Scoggins
<anywho.scoggins at gmail.com>wrote:

> I'm trying to set the values for TerminalServicesHomeDrive and
> TerminalServicesHomeDirectory through Python.
>
> I have this code that works in Powershell but need to get the same
> functionality in python. It looks like IADsTSUserEx
> <http://msdn.microsoft.com/en-us/library/windows/desktop/aa380823%28v=vs.85%29.aspx>object
> owns those permissions but how would I access that object.
>
> #Powershell code that works
> <code>
> $TSHomeDrive = 'I:'
> $TSHomeDirectory = '\\myserver\homehomedrive$\'
> $aduser = [adsi] $ldapstr
> $aduser.TerminalServicesHomeDirectory =
> $TSHomeDirectory+$aduser.samaccountname
> $aduser.TerminalServicesHomeDrive = $TSHomeDrive
> $aduser.setinfo()
> </code>
>
> I've tried these below but get property not found errors:
>
> #Python code that doesn't work
> <code>
> import active_directory as ad
>
> aduser = ad.find_user()
> aduser.TerminalServicesHomeDirectory #fails with attribute error
> aduser.com_object.TerminalServicesHomeDirectory #fails with attribute error
>
> #as you would expect, these fail too, with attribute not found errors
> aduser.com_object.Put('TerminalServicesHomeDirectory', tdhdir)
> aduser.com_object.SetInfo()
> </code>
>
> Any thoughts how I could modify those attributes via Python?
>
> Thanks in advance,
>
> Daniel Scoggins
>



-- 
Daniel Scoggins Jr
571-345-4864
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120209/9ce36260/attachment.html>


More information about the python-win32 mailing list