开发者

How to retrieve Active Directory environment and session information with VB.Net

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 onl开发者_如何转开发y implemented on Server 2008. There must be another way for older version.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜