WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI LDAP CDO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ADSI COM Example - List Connected Sessions

 Keywords:  ADSI COM Enumerate List Connected User Sessions 

Question:

I was wondering if Winbatch has a native function that would allow me to query the ammount of users accessing a shared drive. I making a load balncing script and this is a key component. Currently I am running the following command from within the DOS shell: net session | find /C "\\"

It gives me what I need, but I would prefer a native Winbatch function. Is this possible?

Answer:

Use ADSI COM to enumerate the connected users and how to define the computer from which they are connecting. Reference: http://msdn.microsoft.com/en-us/library/aa746331(VS.85).aspx
;***************************************************************************
;**
;**        Use ADSI COM to enumerate the connected users and
;**        how to define the computer from which they are connecting.
;**
;***************************************************************************

; Replace DOMAIN & SERVER with the appropriate domain and server names
Domain = "www"
SERVER = "serv909"

adsFSOps = ObjectGet("WinNT://":DOMAIN:"/":SERVER:"/lanmanserver")

; Enumerate sessions
adsSessions = adsFSOps.Sessions
ForEach adsSession In adsSessions
  Pause( "Sessions", "User: " : adsSession.User : @LF :"Computer: " : adsSession.Computer )
Next

; Clean up
adsFSOps = 0
Exit

Article ID:   W18048
Filename:   ADSI COM Example - List Connected Sessions.txt
File Created: 2009:10:08:09:52:50
Last Updated: 2009:10:08:09:52:50