No navigation frame on the left?  Click here.

NetSessionDel

This sample actually does something useful: it queries a server for its current list of sessions with NetSessionEnum() and selectively closes some of them with NetSessionDel(). Before you start playing with it -- do remember the "-d" switch ("d" as in "debug") which makes the program skip the call that actually closes the connection. Otherwise, you might find yourself some new enemies in a real hurry.

The intent of this utility is the closing of sessions to avoid reaching the 2,200 pipe limit on a heavily used domain controller. To that end, you can supply a minimum idle time (-i switch); sessions with activity during the last N seconds are not killed. You may also specify either a list of user names whose sessions should not be closed (-u switch), or the -n switch which protects all those sessions from being deleted that are associated with a user name. A -c switch is also available; it lets you create a list of client computer names whose sessions are also exempt from being closed. The program can run in a loop until stopped with Ctrl-C or Ctrl-Break; to do that, just use the -p switch to set a pause (in seconds) between successive examinations of the session list. Finally, -s permits setting a server name (with backslashes, please). To check the local machine's session list, just omit the "-s" (and the server name, of course).

Here is a sample command line (all on one line, please):

killidle -s \\my-dc -c bar -c spartacus -c alison
  -c coolie -c mailbag -n -i 1800 -f 3

This will close unnamed (-n) sessions on my domain controller, excluding a few machines doing useful things (-c). Only sessions that were idle for more than 1800 seconds (-i) just prior to our check are closed. After each check, there is a three-second pause (-f) before the next check begins.

Need help? Just invoke the program with an invalid argument, or with an invalid switch (such as "-?"). Need more help? Think the code deserves more comments <g>? Send email (see at bottom for link), or use the feedback page.

killidle.cpp, 10 KB