views:

12

answers:

1

I'd like to be able to get and set the different information for a user in Active Directory on Windows Server 2003 under Environment and Session tabs through a VB.Net application. I am familiar with System.DirectoryService but I can not find the correct attributes for these particular tabs. For example, I'd like to check "Connect Printer at logon" or set "Idle session limit".

I've found the "ms-TS-Connect-Printer-Drives Attribute" and other attributes like it but they are only implemented on Server 2008. There must be another way for older version. Thank you!

A: 

I've found the answer after many research.

There is some information you just can't get and set through DirectoryServices under Windows Server 2003, especially under tabs like Session, Environment, Terminal Service, etc There is a DLL that can do it for you: TSUSEREX.dll found in Windows/System32.

Adding a reference to that library in your visual studio project, here is an example on how to use it to get what you need:

Have a directory entry(dirEntry) pointing on the user you wish to work on.

Dim oUser As ADsTSUserEx = CType(dirEntryUsr.NativeObject, ADsTSUserEx)
oUser.MaxIdleTime = 10
oUser.ConnectClientPrintersAtLogon = 1

This will set the max idle connection time to 10 minutes and have the printer connected automatically.