Shared folders open sessions

Posted on 2011-04-26
Last Modified: 2012-05-11
Hi everyone,

I have a problem with a server with one of my customers, The sessions of the shared folders always stays open. I can terminate the open sessions with the following script, but I only want to kill the sessions which have no open files.

How should you modify the following script that it only terminates the connections with no open files?

The server is a windows small business server 2003.

Thanks in advance!

Kind regards
Set objConnection = GetObject("WinNT://sbsserver/LanmanServer")
Set colSessions = objConnection.Sessions

For Each objSession in colSessions

Open in new window

Question by:Silencer001
    LVL 5

    Expert Comment

    What value do you have set for the sessions to timeout?
    LVL 8

    Accepted Solution

    This should do it.  The Resources collection gets all users who have an open file.  Then it terminates any user without an open file.
    Set dResources = CreateObject("Scripting.Dictionary")
    Set oConnection = GetObject("WinNT://sbsserver/LanmanServer")
    Set cResources = oConnection.Resources
    For Each oResource in cResources
        If Not dResources.Exists(LCase(oResource.User)) Then dResources.Add LCase(oResource.User), 1
    Set cResources = Nothing
    Set cSessions = oConnection.Sessions
    For Each oSession in cSessions
        If Not dResources.Exists(LCase(oSession.User)) Then _
    Set cSessions = Nothing
    Set oConnection = Nothing
    Set dResources = Nothing

    Open in new window


    Author Comment

    Wow worked like a charm, really pro stuff!!

    Thank you so much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now